我使用here找到的代码和教程实现了一个QuickAction菜单。
我有一个ListView,我用SQLite DB中的记录填充,当单击一条记录时,会显示QuickAction菜单。我不知道该怎么办是使用QuickAction项对所选记录采取措施(例如,选择QuickAction项时更新数据库中的选定记录)。
这是我的QuickAction onclick监听器:
quickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener()
{
@Override
public void onItemClick(QuickAction source, int pos, int actionId)
{
ActionItem actionItem = quickAction.getActionItem(pos);
if (actionId == VIEW)
{
[view the record]
}
else if (actionId == UPDATE)
{
[update a value in the db]
}
else
{
[do something else to the record]
}
}
});
答案 0 :(得分:0)
传递给OnItem只查看位置。要更新记录,您可以使用putExtra方法:
quickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener()
{
@Override
public void onItemClick(int pos)
{
if (pos == 0)
{ //View item selected
Toast.makeText(YourCurrentActivity.this, "View item selected",
Toast.LENGTH_SHORT).show();
}
else if (pos == 1)
{ //Update item selected
Toast.makeText(YourCurrentActivity.this, "Update item selected",
Toast.LENGTH_SHORT).show();
}
else if (pos == 2)
{ //Other item selected
Toast.makeText(YourCurrentActivity.this, "Other item selected",
Toast.LENGTH_SHORT).show();
}
}
});