Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my code json and listview are working properly
But when I use alert dialog to display custom listview app crashes:

Java
LayoutInflater li = LayoutInflater.from(MainActivity.this);
                            View view = li.inflate(R.layout.flist, null);

                            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
                            alertDialogBuilder.setView(view);

Java
ArrayList<Food> list = new ArrayList<Food>();
FoodList adapter = new FoodList(MainActivity.this, (ArrayList<Food>)list);
                            foodlist.setAdapter(adapter);
                            alertDialogBuilder
                                    .setCancelable(false)

                                    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int id) {
                                            dialog.cancel();
                                        }
                                    });

                            // create alert dialog
                            AlertDialog alertDialog = alertDialogBuilder.create();
                            // show it
                            alertDialog.show();



xml: flist.xml

<listview> android:id="@+id/foodlist"
android:layout_width="fill_parent"
android:layout_height="match_parent">Can you help??

Its showing error on
foodlist.setAdapter(adapter);

Thanks in advance

What I have tried:

Tried lot :
http://stackoverflow.com/questions/5250765/android-custom-list-dialog

http://stackoverflow.com/questions/15762905/how-can-i-display-a-list-view-in-an-android-alert-dialog

http://stackoverflow.com/questions/10333730/how-to-make-baseadapter-show-alertdialog-android-application
Posted
Comments
Richard MacCutchan 15-Mar-16 16:57pm    
What error?
Member 12288686 16-Mar-16 2:13am    
Yes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900