List of usage examples for android.view MenuItem getItemId
public int getItemId();
From source file:com.example.android.touroflondon.MainActivity.java
/** * Called when an option item is selected. * * @param item//ww w. j a v a2 s .c om * @return */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_poi: { // Show the POI fragment // Initialise if required if (mPoiListFragment == null) { mPoiListFragment = new PoiListFragment(); } // Display the fragment getFragmentManager().beginTransaction().replace(R.id.fragment_container, mPoiListFragment) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).addToBackStack(null).commit(); // Hide the POI action item item.setVisible(false); // Enable up navigation from POI fragment getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setTitle(R.string.menu_poi_home_action); return true; } case android.R.id.home: { // Home action item, close POI fragment closePoiFragment(); return true; } case R.id.menu_about: // Display about dialog new AboutDialog().show(getFragmentManager(), null); return true; } return super.onOptionsItemSelected(item); }
From source file:com.codebutler.farebot.activities.MainActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { if (item.getItemId() == R.id.delete_card) { long id = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).id; Uri uri = ContentUris.withAppendedId(CardProvider.CONTENT_URI_CARD, id); getContentResolver().delete(uri, null, null); return true; }// w w w .j a v a2 s . c o m return false; }
From source file:edu.cwru.apo.Home.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.updateMenuItem: if (phoneDB == null) phoneDB = new PhoneOpenHelper(this); if (database == null) database = phoneDB.getWritableDatabase(); API phoneApi = new API(this); String[] params = { "0" }; if (!phoneApi.callMethod(Methods.phone, this, params)) { Toast msg = Toast.makeText(this, "Error: Calling phone", Toast.LENGTH_LONG); msg.show();/*from w w w .j av a 2 s . c om*/ } return true; case R.id.updateApp: API updateAppApi = new API(this); if (!updateAppApi.callMethod(Methods.checkAppVersion, this)) { Toast msg = Toast.makeText(this, "Error: Couldn't get app version", Toast.LENGTH_LONG); msg.show(); } default: return super.onOptionsItemSelected(item); } }
From source file:com.netpace.expressit.activity.UploadImageStoryActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (!isGalleryPhoto) { this.onBackPressed(); } else {/*from w w w. j a v a 2s . c o m*/ Intent intent = new Intent(UploadImageStoryActivity.this, MediaOptionsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } return true; case R.id.menu_item_img_gallery: if (isValidate()) { // close the keyboard. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(titleTextView.getWindowToken(), 0); getMediaKeyFromRemoteServer(); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.qrankforAndroid.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }// w w w. j av a2 s . c o m switch (item.getItemId()) { default: return super.onOptionsItemSelected(item); } }
From source file:com.miz.mizuu.fragments.CoverSearchFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { getActivity().onBackPressed();/*from ww w .jav a 2 s . c o m*/ return true; } item.setChecked(true); if (item.getItemId() == 0) { mImageUrls.clear(); for (int i = 0; i < mCovers.size(); i++) mImageUrls.add(mCovers.get(i).getUrl()); if (mAdapter != null) ((BaseAdapter) mGridView.getAdapter()).notifyDataSetChanged(); } else { mImageUrls.clear(); for (int i = 0; i < mCovers.size(); i++) if (mCovers.get(i).getLanguage().equals(mItems[item.getItemId()])) mImageUrls.add(mCovers.get(i).getUrl()); if (mAdapter != null) ((BaseAdapter) mGridView.getAdapter()).notifyDataSetChanged(); } return super.onOptionsItemSelected(item); }
From source file:de.elanev.studip.android.app.frontend.forums.ForumEntryFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (isAdded()) { switch (item.getItemId()) { case android.R.id.home: getActivity().onBackPressed(); return true; case R.id.forum_area_add: Bundle args = new Bundle(); args.putString(ForumEntry.ID, mEntryId); args.putSerializable(ForumEntryComposeFragment.ENTRY_TYPE, ForumEntryComposeFragment.EntryType.REPLY_ENTRY); Intent intent = new Intent(getActivity(), ForumEntryComposeActivity.class); intent.putExtras(args);//from w w w . j av a 2 s .co m startActivityForResult(intent, CREATE_ENTRY); return true; default: return super.onOptionsItemSelected(item); } } return true; }
From source file:com.skalski.raspberrycontrol.Activity_GPIO.java
public boolean onOptionsItemSelected(MenuItem element) { switch (element.getItemId()) { case R.id.reconnect: if (client.isConnected()) { Log.w(LOGTAG, LOGPREFIX + "you are already connected to the server"); toast_connection_error(getResources().getString(R.string.error_msg_5)); } else {// ww w . j ava2s . c o m if (!client.connect()) { Log.w(LOGTAG, LOGPREFIX + "can't connect to server - please try once again"); toast_connection_error(getResources().getString(R.string.error_msg_4)); } else { client.setFilter(TAG_GPIOSTATE); client.setHandler(clientHandler); Log.i(LOGTAG, LOGPREFIX + "reconnecting to server"); } } break; } return true; }
From source file:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_add: startActivityForResult(new Intent(this, RecipeEditor.class).putExtra(RecipeEditor.NEW_RECIPE, true), ACTION_ADD);/*from w w w.ja va2s . c o m*/ return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.sat.sonata.MenuActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection. switch (item.getItemId()) { case R.id.stop: Log.d("SITTING", "Inside stop case"); //stopService(new Intent(this, SonataService.class)); return true; case R.id.recognise: String imagePath = getIntent().getStringExtra("image"); getIntent().removeExtra("image"); Log.d("SITTING", imagePath); HttpPost postRequest = new HttpPost("http://129.31.195.224:8080/picUpload"); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); try {/*from ww w . j a va 2 s . c o m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); Bitmap bitmap; BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; bitmap = BitmapFactory.decodeFile(imagePath, options); bitmap.compress(Bitmap.CompressFormat.JPEG, 75, bos); byte[] data = bos.toByteArray(); ByteArrayBody bab = new ByteArrayBody(data, "music.jpg"); reqEntity.addPart("music", bab); postRequest.setEntity(reqEntity); HttpPost[] posts = new HttpPost[1]; posts[0] = postRequest; GetImageTask getImageTask = new GetImageTask(); getImageTask.execute(posts); } catch (Exception e) { Log.v("Exception in Image", "" + e); // reqEntity.addPart("picture", new StringBody("")); } default: return super.onOptionsItemSelected(item); } }