How can I set title of the context menu from the selected Listview item? This below is my main activity.
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);
}
.....
.....
I need to set menu.setHeaderTitle to R.id.name. I’m aware of another similer question but it don’t mention about dealing with a complex ListView with multiple textviews.
Use the
ContextMenuInfoparameter from theonCreateContextMenu()method: