我有一个场景,当我点击按钮时,我想要弹出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
请帮助我实现这一目标.
最佳答案
在警报对话框构建器中更改以下行
原文链接:https://www.f2er.com/android/430963.htmlListView lv2 = (ListView) getActivity().findViewById(R.id.toplist);
同
ListView lv2 = (ListView) view.findViewById(R.id.toplist);