抱歉愚蠢的问题,但我应该更改/添加该代码 – 通过短暂单击列表视图中的项目来显示上下文菜单?
public class MyActivity extends ListActivity implements AdapterView.OnItemClickListener { static final String[] COUNTRIES = new String[]{ "Afghanistan","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antarctica" }; /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter<String>(this,R.layout.list_item,COUNTRIES)); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(this); } public void onCreateContextMenu(ContextMenu menu,View v,ContextMenu.ContextMenuInfo menuInfo) { Log.e("sdklfjsdkljfl"," <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< "); menu.setHeaderTitle("HELLO"); } public void onItemClick(AdapterView<?> adapterView,View view,int i,long l) { Log.e("kjhasjkdhkas","sdkhjkhskaf"); this.openContextMenu(view); } }