Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Date Calendar Java Android Example


Calendar cal = new GregorianCalendar(), int year = cal.get(Calendar.YEAR),
ERA, MONTH, DAY_OF_MONTH, DAY_OF_WEEK, Android example code.

public class MainActivity extends Activity {
TextView txtV;
	Context cntx;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        txtV = (TextView)findViewById(R.id.idLabel);
        cntx = this;
        Calendar cal = new GregorianCalendar();

     int era = cal.get(Calendar.ERA);  // 0 B.C. before Christ, 1 Anno Domini              
     txtV.setText(txtV.getText() +"

" + era); int year = cal.get(Calendar.YEAR); // 2011 txtV.setText(txtV.getText() +"
" + year); int month = cal.get(Calendar.MONTH); // 0 is Januar txtV.setText(txtV.getText() +"
" + month); int day = cal.get(Calendar.DAY_OF_MONTH); // 1 to 31 txtV.setText(txtV.getText() +"
" + day); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday, 2=Monday ... txtV.setText(txtV.getText() +"
" + dayOfWeek); } }

397LW NO topic_id



Další témata ....(Topics)


77

break statement in Java Android example | break-statement-in-java-android-example


break statement in Java Android basic example

MainClass.java

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "end" };
		
		for (int i = 0; i < arrayOfString.length; i++) {
				System.out.println(arrayOfString[i]);
				if(i > 2) 
					break; // end of loop
		}
	}
}
/*
nothing
Hello
people
bye-bye
*/
270

setTesting(boolean) from the type AdRequest is deprecated | settestingboolean-from-the-type-adrequest-is-deprecated


Admob testing on emulator issue.
Android Eclipse code warning:
setTesting(boolean) from the type AdRequest is deprecated
Solution:
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);


AdView adView = new AdView(this, AdSize.BANNER, "a14d9..........");//MY_AD_UNIT_ID
AdRequest adRequest = new AdRequest();
		adRequest.setTesting(true); // deprecated

		adRequest.addTestDevice(AdRequest.TEST_EMULATOR); // OK
		adView.loadAd(adRequest);

269

Eclipse revert old version Android Development Tools | eclipse-revert-old-version-android-development-tools


If you have trouble with compilation of new project after you make a update of android development tools you can go back to old version of the tools.




    • Open Help > About Eclipse... use the menu > About...

    • Click the "Installation Details" button.

    • Select the "Installation History" tab.

    • Select one of the previous configurations.

    • Click the "Revert" button at the bottom.





eclipse-revert-android-development-tools-1

eclipse-revert-android-development-tools-2


327

How to create mobile friendly page | how-to-create-mobile-friendly-page


If using Wordpress:
- update Wordpress
- download Plugin Any Mobile Theme Switcher and upzip into yourweb/wp-content/plugins/
- open Wordpress Dachboard on yourweb
- set defalut theme for desktop (Appearance - Theme)
- set themes for mobile users Settings - Any Mobile Theme Switcher for example Twentyfourteen theme
- preview page
- test page on Mobile Friendly Test
135

Draw Arc Android basic example | draw-arc-android-basic-example


drawArc(), Canvas, Paint, setStyle()

public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}

		@Override
		protected void onDraw(Canvas canvas) {

			canvas.drawColor(Color.CYAN);
			Paint p = new Paint();
			// smooths
			p.setAntiAlias(true);
			p.setColor(Color.RED);
			p.setStyle(Paint.Style.STROKE); 
			p.setStrokeWidth(5);
			// opacity
			//p.setAlpha(0x80); //
 
			RectF rectF = new RectF(50, 20, 100, 80);
			canvas.drawOval(rectF, p);
			p.setColor(Color.BLACK);
			canvas.drawArc (rectF, 90, 45, true, p);
		}

	}
}



Editace: 2011-09-29 13:32:10
Počet článků v kategorii: 397
Url:date-calendar-java-android-example
Share
Share
Tweet