抱歉问一个愚蠢的问题,但我应该在那段代码中更改/添加什么内容,才能通过在列表视图中短按项目来显示上下文菜单?
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);
}
}