Android QuickAction and SQLite DB Updates

179 views Asked by At

I have implemented a QuickAction menu using the code and tutorial found here.

I have a ListView that I populate with records from a SQLite DB and when a record is clicked the QuickAction menu is displayed. What I don't know how to do is take action on the selected record using the QuickAction items (e.g. update the selected record in the DB when a QuickAction item is selected).

Here is my QuickAction onclick listener:

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]
        } 
    }
  });
1

There are 1 answers

0
Dany On

Pass to OnItemClick only the position. For updating records you can use putExtra methods:

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();
    }                               
   }                            
});