将自定义ListView添加到“警报"对话框

编程入门 行业动态 更新时间:2024-10-08 06:23:30
本文介绍了将自定义ListView添加到“警报"对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我也想添加自定义列表视图一个警报对话框,当我从列表中选择一个项目并单击(setPositiveButton)对话框关闭并且文本更改成功时,它仍然可以正常工作,但是当我再次单击乘客按钮以查看时或更改选择导致应用程序不幸停止

I want to add custom list view too a alert dialog it works fine when i select a item from list and click the (setPositiveButton) the dialog close and the text is changed successful but when i click again on the passenger button to view or for change selection than application stops unfortunately

public void onClick(View v) { // TODO Auto-generated method stub AlertDialog.Builder builder= new AlertDialog.Builder(MainActivity.this); builder.setCancelable(true); builder.setView(v); builder.setPositiveButton("Done", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id){ dialog.cancel(); } }); builder.setView(listView); AlertDialog dialog= builder.create(); dialog.show(); } });

推荐答案

AlertDialog.Builder builderSingle = new AlertDialog.Builder(YourActivity.this); List<Requests> requester = new ArrayList<>(); final NameAdapter AlertDialogueAdapter = new NameAdapter(this, R.layout.your_custom_layout, requester); AlertDialogueBuilder.add(new Requests("Hello","StackOverF")) builderSingle.setIcon(R.drawable.avatar); builderSingle.setTitle("Select Message by,"); builderSingle.setNegativeButton("cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builderSingle.setAdapter(AlertDialogueAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Requests req = AlertDialogueAdapter.getItem(which); AlertDialog.Builder builderInner = new AlertDialog.Builder(ViewSpecialMessage.this); builderInner.setMessage(req.getKey()); builderInner.setTitle(req.getName()); builderInner.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog,int which) { dialog.dismiss(); } }); builderInner.show(); } }); builderSingle.show(); public class Requests{ private String name; private String key; public Requests(){ } public Requests(String name, String key){ this.name = name; this.key = key; } public String getName() { return name; } public String getKey() { return key; } } public class NameAdapter extends ArrayAdapter<Requests>{ public NameAdapter(Context context, int resource, List<Requests> objects) { super(context, resource, objects); } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.name_adapter_layout, parent, false); } final Requests message = getItem(position); TextView NameOfRequester = (TextView) convertView.findViewById(R.id.RequesterName); ImageView ImgOfRequester = (ImageView) convertView.findViewById(R.id.RequesterImage); NameOfRequester.setText(message.getName()); return convertView; } }

更多推荐

将自定义ListView添加到“警报"对话框

本文发布于:2023-11-11 08:40:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577914.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   警报   对话框   ListView   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!