In my code json and listview are working properly
But when I use alert dialog to display custom listview app crashes:
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);
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();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
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