1

我已经使用此处找到的代码和教程实现了 QuickAction 菜单。

我有一个 ListView,我用 SQLite DB 中的记录填充它,当单击记录时,会显示 QuickAction 菜单。What I don't know how to do is take action on the selected record using the QuickAction items (eg update the selected record in the DB when a QuickAction item is selected).

这是我的 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]
        } 
    }
  });
4

1 回答 1

0

仅将位置传递给 OnItemClick。要更新记录,您可以使用 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();
    }                               
   }                            
});
于 2012-08-24T10:00:57.267 回答