简体   繁体   中英

Displaying AlertDialog when a button in listview is clicked

How to display an AlertDialog when a button in listview is clicked. NOTE : The Listview is created using Custom Adapter.

The listview consists of 3 TextViews and a Button. So I need to know how to display an alertdialog when I click the button present in the listview content.

Thanks in advance :)

Within your Adapter.getView method, just set a View.OnClickListener to the Button with an anonymous inner type. For example:

myButton.setOnClickListener(new View.OnClickListener() {            
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                builder.setMessage("This is just an example!");
                builder.create().show();
            }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM