不能弄清楚什麼是錯我的代碼:入門的項目列表視圖中選擇使用右鍵菜單
registerForContextMenu(lv_myhitshotlists);
AdapterContextMenuInfo menuinfo = null;
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
/*menu.setHeaderTitle("Item Operations");
menu.add(0, v.getId(), 0, "Edit Film");
menu.add(0, v.getId(), 0, "Delete Film");*/
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_myfilm_list,menu);
menuinfo = (AdapterContextMenuInfo) menuInfo;
menu.setHeaderTitle("Options");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
try{
menuinfo = (AdapterContextMenuInfo) item.getMenuInfo();
AdapterView.AdapterContextMenuInfo info= (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
Long ids = madapter.getItemId(info.position);//what item was selected is ListView
i = ids.intValue();
switch (item.getItemId()) {
case R.id.menu_edit_myfilm:
intHitshotEdit = new Intent(MyHitshotListActivity.this,MyHitshotInfoEditActivity.class);
intHitshotEdit.putExtra("video_id", myList.get(i).getid());
intHitshotEdit.putExtra("video_title", myList.get(i).getTitle());
Toast.makeText(getApplicationContext(),myList.get(i).getTitle(), Toast.LENGTH_SHORT).show();
//intVideodetails.putExtra("video_desc", myList.get(i).get);
startActivity(intHitshotEdit);
overridePendingTransition(R.anim.slideinfromright,R.anim.slideouttoleft);
//intVideoUpload.putExtra("title",""+info.);
return true;
case R.id.menu_delete_myfilm:
return true;
default:
}
}catch(Exception e)
{
e.printStackTrace();
}
return super.onContextItemSelected(item);
}
每一次Long ids
將返回0。I在onpostexecute我將數據綁定到列表視圖()像這樣的AsyncTask的一部分:
public void setAdapterToListview(ArrayList<MyHitshotListData> myList) {
madapter=new MyHitshotListAdapter(context, myList);
lv_myhitshotlists.setAdapter(madapter);
}
MyHitshotListAdapter是延伸適配器底座適配器class.What是錯誤的?爲什麼id的值總是零??的position
值未來的權利。
但是你爲什麼要這樣做?直接得到索引像'int index = info.position;' –
indexview的索引對嗎? – kgandroid
雅,你會得到特定索引的數據使用'video_id = myList.get(index).getid();' –