我正在做一个项目,我有一个在运行时创建的多个列表视图的视图,每个列表视图都加载数据库的特定行。我想实现一个上下文菜单。问题是如何获取列表视图的行来检索数据库的 ID?如何在上下文菜单中获取我的列表适配器?或其他一些解决方案。谢谢!这是代码的一部分...
private void makeView(){
yearsArray = db.getUniqueYears(TABLE_NAME);
for (int i = 0; i < yearsArray.size() ; i++){
list = db.getDocByYear(TABLE_NAME, yearsArray.get(i));
custom_adapter = new Document_adapter(this, list);
ListView lv = new ListView(this);
lv.setAdapter(custom_adapter);
lv.setBackgroundResource(R.drawable.title_container_bg);
registerForContextMenu(lv);
}
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater mi = getMenuInflater();
mi.inflate(R.menu.doc_options, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
/*
*/
return super.onContextItemSelected(item);
}