Android alertdialog Dynamic Update inside the ListView data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.