final int MENU_ADD=0;
final int MENU_DELETE=1;
final int MENU_VIEW=2;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, MENU_ADD, 0, "Add").setIcon(R.drawable.ic_launcher);
menu.add(0, MENU_DELETE, 0, "Delete");
menu.add(0, MENU_VIEW, 0, "View");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case MENU_ADD:
Log.v("menu","Add clicked");
return true;
case MENU_DELETE:
Log.v("menu","View clicked");
return true;
case MENU_VIEW:
Log.v("menu","View clicked");
return true;
default:
break;
}
return true;
}
Pages
Showing posts with label example. Show all posts
Showing posts with label example. Show all posts
June 1, 2012
Example : Android Menu/Selected snippet.
May 31, 2012
Example: Shared Preference Getter/Setter
import android.content.Context;
import android.content.SharedPreferences;
public class Util {
private static String tag="util";
private static String KP_PREF="kp_pref";
private SharedPreferences mSharedPref;
public static int getIntValue(Context ctx,String key,int defval)
{
SharedPreferences pref = ctx.getSharedPreferences(KP_PREF,Context.MODE_PRIVATE);
int usageCount = pref.getInt(key, defval);
return usageCount;
}
public static void putIntValue(Context ctx,String key,int defval)
{
SharedPreferences pref = ctx.getSharedPreferences(KP_PREF,Context.MODE_PRIVATE);
pref.edit().putInt(key,defval).commit();
}
}
Subscribe to:
Posts (Atom)