registerForContextMenu(listView);
}
public void OnCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo){
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(R.id.item1);
menu.add(R.id.item2);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item){
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch(item.getItemId()){
case R.id.item1:
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.putExtra("sms_body", "TU-Do List Item: " + mAdapter.getItem((int)info.id));
smsIntent.putExtra("address", "2924699");
smsIntent.setType("vnd.android-dir/mms-sms");
startActivity(smsIntent);
return true;
case R.id.item2:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "cosc490spring2014@gmail.com");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "New TU-Do Item");
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, mAdapter.getItem((int)info.id));
startActivity(emailIntent);
return true;
default:
return super.onContextItemSelected(item);
}
}
所以我把这个代码放到了我的android应用程序
我不明白为什么当我点击我的listview时,contextMenu仍然不会弹出。任何帮助将不胜感激
好的,因为这非常简单,但是添加一个有效的onClickListener也会有所帮助。
答案 0 :(得分:1)
onCreateContextMenu
必须使用小字母编写。
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)...