我正在尝试使用put extra将额外信息发送到用户单击上下文菜单时的其他活动。上下文菜单会加载活动,但信息不会显示在其他活动上。下面的代码显示了我的尝试。
public void in(int position) {
// gets the position of the item in my array list
Cars c = cars.get(position);
Intent i = new Intent(this, DisplayMessageActivity.class);
i.putExtra("TITLE", c.getCarsTitle());
startActivity(i);
}
// create context menu
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.cars_menu_layout, menu);
}
// runs on long click
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
switch (item.getItemId()) {
case R.id.register:
// runs the method that starts the intent
in(0);
return true;
case R.id.view:
return true;
default:
return super.onContextItemSelected(item);
}
}
答案 0 :(得分:1)
尝试使用
i.putExtra("TITLE", c.getCarsTitle().toString);