views:

48

answers:

1
@Override  
 public boolean onContextItemSelected(MenuItem item) {  
  if(item.getTitle()=="Remove"){
   AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
   quotesAdapter.remove(quotes.get((int)info.id));
   quotesAdapter.notifyDataSetChanged();
   listView.setAdapter(quotesAdapter);
   serializeQuotes();
  }  
  else {
   return false;
  }  

  return true;  
 }  

Doesn't do anything. If I add

this.quotesAdapter = new QuoteAdapter(this, R.layout.mainrow, quotes);

Removal works, but I don't think is the right way of doing things. I'm not sure what is wrong?

A: 

If quotes is a Java array, that is unmodifiable at runtime. Try using an ArrayList<> instead.

If quotes is a Cursor, you need to delete the row from the underlying database, then requery() the Cursor.

CommonsWare
quotes is an ArrayList<Quote>
Sheehan Alam
Try using `info.position`, then, instead of `info.id`. `position` is the index into your array; `id` probably has no value.
CommonsWare
both info.position and id return a value as I can print the object to the console. Unfortunately, it is still not being removed from the list.
Sheehan Alam