0
我創建使用SimpleCursorAdapter
列表視圖,在列表中登記的上下文菜單...更新列表項onContextItemSelected
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(...));
}
問候
什麼'lv.getSelectedItem();'將返回? – dakait
在您的適配器中,您設置了ArrayAdapter,因此getSeletedItem將返回選定索引處的項目。 –
即時通訊不使用ArrayAdapter我的適配器看起來像'public class MyListAdapter extends SimpleCursorAdapter {'獲取項目後,我如何獲取文本視圖? – dakait