Monday 22 October 2012

android: toggle and switch buttons


 <ToggleButton
            android:id="@+id/switchitem"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/toggle"
            android:checked="true" 
            android:textOn=""
            android:textOff=""/>

and the drawable will be :
toggle_me_on.png

toggle_me_off.png

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true"
        android:drawable="@drawable/toggle_me_on" /> <!-- pressed -->
    <item android:drawable="@drawable/toggle_me_off" /> <!-- default/unchecked -->
</selector>

android: Long string in ListView's items


android:singleLine="true"
android:ellipsize="end"

android: How to make keypad hidden when the activity is started

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

Friday 19 October 2012

android: How to erase Activity stack in Android?

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
or 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Monday 15 October 2012

android: can't call String.isEmpty()


Use String.length() == 0 instead. It is backwards compatible all the way back to JDK 1.0 ... and with J2ME as well.
String.equals("") is another alternative.

android: Develop Android's application for all the versions

In Manifest file just add


<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10">

Wednesday 10 October 2012

android: Manually Select the Spinner Item


Spinner s = (Spinner) findViewById(R.id.spinner_id);
int i = adapter.getPosition("blue");
s.setSelection(i);