如何从选择的Listview
项设置上下文菜单的标题?以下是我的主要活动。
public class OListActivity extends ListActivity {
......
......
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
registerForContextMenu(getListView());
......
......
MatrixCursor cursor;
cursor = NameManager.getnameList();
startManagingCursor(cursor);
String[] from = { "name", "info", "status", BaseColumns._ID };
int[] to = { R.id.name, R.id.info, R.id.status };
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.row, cursor, from, to);
setListAdapter(adapter);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Menu");// TODO Change to name of selected listview item.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
.....
.....
我需要将
menu.setHeaderTitle
设置为R.id.name
。我知道有另一个类似的问题,但它没有提及如何处理具有多个文本视图的复杂ListView
。
menu.setHeaderTitle(cursor.getString(1))
。 - Binoy BabugetString()
方法需要一个int
而不是一个String
。我很累了,我一直在想到方法cursor.getString(cursor.getColumnIndex("name"));
。 - user