Android ListItem's item popup alert dialog
I have a twist on a common question I've seen in here, and I'm puzzled.
What I need is simply a dialog box for each sub item of a list item. I have seen a dialog for a list item, but I need it down to the list item's item. Currently I've tried doing that within the adapter when inside the getView() method.
For example:
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater li = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(_resourceId, null);
}
string description = "howdy Test";
TextView description = (TextView) v.findViewById(R.id.description);
description.setText(description );
description.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
AlertDialog.Builder dia = new AlertDialog.Builder(view.getContext());
dia.setTitle(view.getContext().getResources().getString(R.string.DESCRIPTION_TITLE));
dia.create();
}
});
}
With that example above, it does go into the onClick() method, 开发者_运维技巧but nothing happens with the AlertDialog. Has anyone else tried this? is there a better way? Even better what am I doing wrong?
Thanks, Kelly
You have to call the show()
method on your dia object.Link here to the android docs!
Instead of adding a OnClickListener to each item in the list view why don't you add one to the listview itself?
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id){
// Create and show dialog here
}
});
精彩评论