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.

Number convert int to string Java Android example code



Convert number int to string Android Java example source code.

int n = 0;

try {
    n = Integer.parseInt("21"));
} catch(NumberFormatException e) {
   System.out.println("Could not parse " + e);
} 
// int to string
String s = String.valueOf(24);

397LW NO topic_id



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


96

onSaveInstanceState() onRestoreInstanceState() basic Android example | onsaveinstancestate-onrestoreinstancestate-basic-android-example



public class MyClass extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       }
	 String sMyText = "some text";
	 int nMyInt = 10;

 @Override
 protected void onSaveInstanceState(Bundle outState) {
     // Save away the original text, so we still have it if the activity
     // needs to be killed while paused.
     outState.putString("my_text", sMyText);
     outState.putInt("my_int", nMyInt);
     Toast.makeText(this, "onSaveInstanceState()", Toast.LENGTH_LONG).show();
Log.i("onSaveInstanceState", "onSaveInstanceState()");
}
 String sNewMyText = "";
 int nNewMyInt = 0;
 
 @Override
 protected void onRestoreInstanceState(Bundle savedInstanceState) {
     super.onRestoreInstanceState(savedInstanceState);
     // restore saved values
     sNewMyText = savedInstanceState.getString("my_text");
     nNewMyInt = savedInstanceState.getInt("my_int");
     Toast.makeText(this, "onRestoreInstanceState()", Toast.LENGTH_LONG).show();
     Log.i("onRestoreInstanceState", "onRestoreInstanceState()");
     
 }
}
142

Create bitmap and draw text into bitmap Android example | create-bitmap-and-draw-text-into-bitmap-android-example



public class ApokusActivity 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) {
			Paint paint = new Paint();
			
			canvas.drawColor(Color.GREEN);
            
           Bitmap b = Bitmap.createBitmap(200, 200, Bitmap.Config.ALPHA_8);
           Canvas c = new Canvas(b);
           c.drawRect(0, 0, 200, 200, paint);
           
           paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
           paint.setTextSize(40);
           paint.setTextScaleX(1.f);
           paint.setAlpha(0);
           paint.setAntiAlias(true);
           c.drawText("Your text", 30, 40, paint);
           paint.setColor(Color.RED);
           
           canvas.drawBitmap(b, 10,10, paint);
		}

	}
}


draw-text-into-bitmap-android

22

RadioButton RadioGroup Java Android example | radiobutton-radiogroup-android-example


RadioButton RadioGroup Android example source code for Android developer
Example for *.xml files

       <RadioGroup android:id="@+id/idRadio_group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:orientation="vertical">

            <RadioButton android:id="@+id/idRadio_1"
                android:text="@string/textLabel_1"/>
            <RadioButton android:id="@+id/idRadio_2"
                android:text="@string/textLabel_2"/>
            <RadioButton android:id="@+id/idRadio_3"
                android:text="@string/textLabel_3"/>

        </RadioGroup>



Example for *.java files

// import
import android.widget.RadioGroup;
// get handle of RadioGroup
RadioGroup  mRadioGroup = (RadioGroup) findViewById(R.id.idRadio_group);

// which RadioButton is selected for example in some function body
         int nUnits = 10; // decimetry
    	 int nIdRadio = mRadioGroup.getCheckedRadioButtonId();
    			if(nIdRadio == R.id.idRadio_1) nUnits = 1; // metr
    			else if(nIdRadio == R.id.idRadio_2) nUnits = 10; // decimetr
    			else if(nIdRadio == R.id.idRadio_3) nUnits = 100; // cm
    			else if(nIdRadio == R.id.idRadio_4) nUnits = 1000; // mm


// listener for RadioGroup Java Android example
       mRadioGroup.setOnCheckedChangeListener(
                new RadioGroup.OnCheckedChangeListener() {
                    public void onCheckedChanged(RadioGroup group,
                            int checkedId) {
                        Log.v("Selected", "New radio item selected: " + checkedId);
                        recordNewUIState();
                    }
                });



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
263

Iterate over each Entry in Map Java Android | iterate-over-each-entry-in-map-java-android


entry put iterate Map HashMap Java Android

Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key27", 27);
for (Map.Entry<String, Integer> entry : map.entrySet())
{
 String str = entry.getKey();
 int n = entry.getValue();
}


Editace Jana Žákovská : 2013-12-09 10:54:53
Počet článků v kategorii: 397
Url:number
Share
Share
Tweet