i have created a custom dialog class
public class NewPost extends Dialog
{
// functionality
}
now my requirement is to create listview inside it. i know we can create textboxes,buttons,dropdown list inside it.
but in order to create list view we should inherit our class from listActivity class
what you suggest is it possible or not if yes then how to achieve this using any interface or what?
You don't really have to extend
listActivity
in order to use listviews.Extending
listActivity
will give you some functionality for free, such asgetListView()
(if I recall the method name correctly), but that can just as well be done manually withfindViewById()
just as any other view.You can use any layout for alert dialogs. If you want a listview I would do it like here
The simplest possible way:
Yes.
You can always use a ListView inside a Dialog. And you definitely don't necessarily need ListActivity to create ListView.
Code may be something like this:
my_layout.xml:
this implementation doesn't require you to make any xml layouts. it was written as a case statement in "onCreateDialog" override, but you can adapt if for your purposes very easily:
because you are making a dialog with only a ListView, you set the onItemClickListener of the ListView, as there isn't one for the basic dialog class.
You can create a custom dialog with this layout:
create a custom layout also for each item if you want:
and then use an arraylist to populate the list and set the view:
References: http://pillsfromtheweb.blogspot.it/2014/10/android-listview-inside-alertdialog.html#links
Result: