我有一个场景,当我点击按钮时,我想要弹出AlertDialog. AlertDialog是一个自定义警报对话框,因为它具有自定义Listview.
我使用以下代码分配AlertDialog OnClick按钮
top.setOnClickListener(new OnClickListener() {
Context mcontext;
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
LayoutInflater li = LayoutInflater.from(getActivity());
View view= li.inflate(R.layout.topingslist,null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
alertDialogBuilder.setView(view);
ListView lv2 = (ListView) getActivity().findViewById(R.id.toplist);
ArrayList
这是我对customlistview的customBaseadapter
public class MyCustomBaseAdapterTop extends BaseAdapter {
private static ArrayList
这是topinglist.xml文件
我将Adapter设置为Listview lv2.setAdapter(arrayAdapter)的行;
给我NullPointerException
请帮助我实现这一目标.
最佳答案
在警报对话框构建器中更改以下行
ListView lv2 = (ListView) getActivity().findViewById(R.id.toplist);
同
ListView lv2 = (ListView) view.findViewById(R.id.toplist);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。