Android - delete a row from list view on button click

Ozi picture Ozi · Sep 9, 2013 · Viewed 29.4k times · Source

i am creating an application in which data is got from a barcode scanner which identifies from an id, and show detail from the database through a web service. i am currently using custom list which has a text view and a button, the data which i want to embed on the textview is displaying correctly...

my question is how do i delete a particular row from the list on the button click .

here is the custom adaptor code.

 public class MyCustomAdapter extends ArrayAdapter<String> 
     {
         public MyCustomAdapter(Context context, int textViewResourceId, ArrayList<String> items) 
         {
             super(context, textViewResourceId, items);
         }

         @Override
         public View getView(int position, View convertView, ViewGroup parent)
         {

             LayoutInflater inflater = FusionMain.this.getLayoutInflater();
             View row = inflater.inflate(R.layout.list_row, parent, false);


             return row;
         }
     } // end MyCustomAdapter

what other function should i be creating in custom adapter ? i am new in android development.. if you need further more detail i can update the question or the code. kindly respond

Answer

Davidjburgos picture Davidjburgos · Sep 9, 2013

To refresh your adapter, just remove the element of your ArrayList and call to

notifyDataSetChanged()

in your adapter.

I think you should watch this example:

http://www.vogella.com/articles/AndroidListView/article.html