Custom Listview In A Dialog
i have a list view , inside this list when click on an item of it ,it will show a custom list inside a dialog box the dialog shows up but its only shows the title of the dialog
Solution 1:
You need to use AlertDialog.Builder
-
Refer this- Docs
Edit -
newAlertDialog.Builder(MyActivity.this)
.setAdapter(yourListAdapter, newDialogInterface.OnClickListener() {
@OverridepublicvoidonClick(DialogInterface dialog, int which) {
//TODO - Code when list item is clicked (int which - is param that gives you the index of clicked item)
}
})
.setPositiveButton("Okay", newDialogInterface.OnClickListener() {
@OverridepublicvoidonClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("Cancel", newDialogInterface.OnClickListener() {
@OverridepublicvoidonClick(DialogInterface dialog, int which) {
}
})
.setTitle("Dialog Title")
.setCancelable(false)
.show();
Solution 2:
@Vishal is right, you needs to use AlertDialog if you needs to inflate view inside your dialog. Here's the example code. Tried the code below.
publicvoidshowDialog(){
AlertDialog.Builderdialog=newAlertDialog.Builder(getContext());
dialog.setTitle("List of likers");
dialog.setCancelable(true);
Viewview= ((Activity)getContext()).getLayoutInflater().inflate(R.layout.likers_list, null);
dbobj = newDataBaseHandler(getContext());
likeItems=dbobj.select_HowlikeComment();
dbobj.CloseDataBase();
ListViewlist= (ListView) view.findViewById(R.id.ListLikersList);
LikersCustomeAdapter adapter= newLikersCustomeAdapter(getContext(), R.layout.likerscustomelist, likeItems);
list.setAdapter(adapter);
dialog.setView(view);
dialog.show();
}
Post a Comment for "Custom Listview In A Dialog"