Android ListItem的item弹出提醒对话框
我对在这里看到的一个常见问题有一个转折,我很困惑。
我需要的只是列表项的每个子项的对话框。我看到了一个列表项的对话框,但我需要它到列表项的项目。目前,我已经尝试在 getView() 方法内的适配器内执行此操作。
例如:
@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();
}
});
}
在上面的示例中,它确实进入了 onClick() 方法,但 AlertDialog 没有任何反应。还有其他人尝试过这个吗?有更好的办法吗?更好的是我做错了什么?
谢谢, 凯莉
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在 dia 对象上调用
show()
方法。此处链接到 Android 文档!You have to call the
show()
method on your dia object.Link here to the android docs!为什么不向列表视图本身添加一个 OnClickListener,而不是向列表视图中的每一项添加一个 OnClickListener?
Instead of adding a OnClickListener to each item in the list view why don't you add one to the listview itself?