1

i am using android studio in listview i have added adapter. when user click delete button from listview item then i want to refresh activity.

adapter delete button definition

    deletebtn =convertView.findViewById(R.id.delete_btn);

    deletebtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        databaseAccess.deleteFavorite(favoriteModel.getWid());

        }
    });

i have tried this code but not working

   deletebtn =convertView.findViewById(R.id.delete_btn);

    deletebtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        databaseAccess.deleteFavorite(favoriteModel.getWid());


            Intent intent1=new Intent(context,FavoriteNameslist.class);

            context.startActivity(intent1);
            ((Activity)context).finish();

        }
    });

i am new to Android - please help
i want when user click on delete button then refresh activity

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • just call notifyDatasetChanged(); – Farrokh Sep 27 '18 at 10:25
  • Possible duplicate of [android: Data refresh in listview after deleting from database](https://stackoverflow.com/questions/27640658/android-data-refresh-in-listview-after-deleting-from-database) – Ali Rehman Sep 27 '18 at 10:30

3 Answers3

0

There is no need to call your Activity to referesh listview you can use

notifyDataSetChanged()

remove the item and set notifyDataSetChanged()

yourList.remove([INDEX]);
arrayAdapter.notifyDataSetChanged();
Bunny
  • 1,044
  • 12
  • 23
0

If you are removing a single item from the view, you need to call

yourAdapter.notifyItemChanged(position) //Just pass the position to this. This also has a default animation. Try this in your adapter class instead of refreshing the layout.
rohiththammaiah
  • 153
  • 1
  • 5
0

Try below lines of code on Deleting Row to Update adapter

 arrayList.remove(position);
 mAdapter.notifyItemRemoved(position);
Android
  • 1,420
  • 4
  • 13
  • 23