我正在使用SimpleCursorAdapter
创建列表视图,其中列表已为上下文菜单注册...
registerForContextMenu(listView);
下面是onContextItemSelection
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (menuItemIndex) {
case 0:{
//perform some action
//then update the adapter
Cursor newCursor = fetchNewCursor();
if(newCursor .moveToFirst()){
adapter.swapCursor(newCursor );
adapter.notifyDataSetChanged();
}//if ends
}// case 0 ends
break;
}//switch ends
}//onContextItemSelected() ends
这会更新我的整个列表视图,我想添加另一个context menu
条目,我只想更新(长)单击的特定列表项。我怎么能这样做......
这就是我Cursor Adapter
的样子
@Override
public View newView (Context context, Cursor cursor, ViewGroup parent) {
return viewInflater.inflate(layout, null);
}
和bindView
方法
@Override
public void bindView(View view, Context context, Cursor cursor) {
super.bindView(view, context, cursor);
TextView t1=(TextView)view.findViewById(R.id.txt_one);
TextView t2=(TextView)view.findViewById(R.id.txt_two);
t1.setText(cursor.getString(...));
t2.getString(cursor.getString(...));
}
问候
答案 0 :(得分:1)
您可以通过调用
从列表中获取所选项目索引lv.getSelectedItemPosition();
然后更新该位置的列表项中的条目并通知适配器:
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (menuItemIndex) {
case 0:{
//perform some action
//then update the adapter
Cursor newCursor = fetchNewCursor();
if(newCursor .moveToFirst()){
adapter.swapCursor(newCursor );
adapter.notifyDataSetChanged();
}//if ends
}// case 0 ends
break;
case 1:
<ItemType> item=lv.getSelectedItem();
<UPdateItem>
adapter.notifyDataSetChanged();
break;
}//switch ends
}//onContextItemSelected() ends