Passing Values from a Context View item to a new intent!
Sorry Im new to android, and im doing a project where i want to edit some data from a item selected in a ListView. the prob is that i dont have any idea on how to pass the data. I select this item, this item is of the type ProjItems(a class to construct the item); it has the gets, string getname(), date getdata(),int getPrec();
and here is where i want to start the new Activity:
public void onCreateContextMenu(ContextMenu menu,View v,ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Selected Project");
menu.add(0, DEL, Menu.NONE, R.string.remove);
menu.add(0, EDIT, Menu.NONE, R.string.edit).setIntent(new Intent(PM_List.this, PM_Edit.class));//here is where i want to pass the info
menu.add(0, TASK_LI开发者_开发知识库ST, Menu.NONE, R.string.task);
menu.add(0, CANCEL, Menu.NONE, R.string.cancel);
}
this info i want to pass to the new activity i will later show it on a textview! Please help me, i will be very much happy, and grateful if you do! best regards to all João Azevedo
So basically you can get the selected item from the underlaying adapter like this.
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
Object my_item = getListAdapter().getItem((int) info.id);
And now you can pass it to the activity using the Intent that will start it like this
Intent intent = new Intent(context, Your_Activity.class);
Bundle extras = new Bundle();
extras.putSerializable("obj_to_pass", my_item);
intent.putExtras(extras);
startActivity(intent);
And than get it from the activity in onCreate method like this
Bundle extras = getIntent().getExtras();
Object my_obj = extras.getSerializable("obj_to_pass");
精彩评论