我有带有自定义适配器的 ListView。直到现在我长按上下文菜单。并重新执行此操作以单击此
getListView().setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
//To register the button with context menu.
registerForContextMenu(getListView());
openContextMenu(getListView());
}
});
只有这个
registerForContextMenu(getListView());
在此更改之前它工作正常,但现在我有 NullPointerExceptioninfo.id
并且我不知道如何修复它。感谢您的回复。
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
Intent i;
Log.d("item id", String.valueOf(item.getItemId()));
switch (item.getItemId()) {
case R.id.spotreba:
i = new Intent(this, SpotrebaActivity.class);
i.putExtra("idAuta", info.id);
startActivityForResult(i, REQUEST_ADD_AUTO);
return true;
.
.
.