所以这是我的问题,我有两个上下文菜单绑定到两个按钮,它们从db表中选择。
final Button bButton = (Button) findViewById(R.id.BeerButton);
bButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerForContextMenu(bButton);
openContextMenu(bButton);
}
});
final Button fButton = (Button) findViewById(R.id.FireButton);
fButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerForContextMenu(fButton);
openContextMenu(fButton);
}
});
}
@Override
public void onCreateContextMenu(ContextMenu cmenu, View v,ContextMenu.ContextMenuInfo cmenuInfo)
{
super.onCreateContextMenu(cmenu, v, cmenuInfo);
if(v.getId() == R.id.BeerButton){
ContextMenu bMenu = cmenu;
bMenu.setHeaderIcon(R.drawable.beer);
bMenu.setHeaderTitle("What's your poison?");
List<bDB> bMenuContainer = bDao.queryBuilder().list();
for (bDB item : bMenuContainer) {
bMenu.add(item.getName() + " " + item.getVolume() + "l " + "(" + item.getCost() + " Kč)");
}
}
else if(v.getId() == R.id.FireButton){
ContextMenu fMenu = cmenu;
fMenu.setHeaderIcon(R.drawable.fire);
fMenu.setHeaderTitle("What do you smoke?");
//blah blah pretty much the same thing
}
}
现在对onContextItemSelected,你能指导我如何做这部分吗?我只需要启动,其余的我将处理,然后将数据写入其他表格以进行进一步的统计。
@Override
public boolean onContextItemSelected(MenuItem item)
{
//somebody cast your magic here, PLEASE!
}
return super.onContextItemSelected(item);
}
提前感谢!