1: The data with the ListView is basically the same as the new one.
2:activity code Example
public class Mainactivity extends appcompatactivity {alertdialog alertdialog; View view; list<string> data = new arraylist<> (); ListView ListView; Arrayadapter<string> adapter; Handler handler=new Handler () {@Override public void Handlemessage (Message msg) {Super.handlemes Sage (msg); Adapter.notifydatasetchanged (); } }; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); for (int i = 0; i < i++) {Data.add ("data:" + i); } view = Getlayoutinflater (). Inflate (r.layout.controller_volume, NULL); Alertdialog = new Alertdialog.builder (this). Settitle ("Dialog ListView Update"). SetIcon (r.mipmap.ic_launcher). SE TView (view). Setpositivebutton ("Return", New Dialoginterface.onclicklistener () {public void OnClick (DialoginterfAce paramanonymousdialoginterface, int paramanonymousint) {}}). Create (); Listview=view.findviewbyid (R.id.listview); Adapter=new arrayadapter<string> (mainactivity.this,android. R.layout.simple_list_item_1,data); Listview.setadapter (adapter); Listview.setonitemclicklistener (New Adapterview.onitemclicklistener () {@Override public void Onitem Click (adapterview<?> Parent, view view, int position, long id) {Data.remove (Data.get (position)); Handler.sendemptymessagedelayed (100,1000); } }); Alertdialog.show (); } }
3:controller_volume.xml Only one ListView
<?xml version= "1.0" encoding= "Utf-8"? ><android.support.constraint.constraintlayout xmlns:android= " Http://schemas.android.com/apk/res/android "android:layout_width=" match_parent " android:layout_height=" Match_parent "> <listview android:layout_width=" match_parent " android:layout_height=" 200DP " android:id= "@+id/listview"/></android.support.constraint.constraintlayout>
Android alertdialog Dynamic Update inside the ListView data