-3
我試圖調整列表視圖到alertDialog,該程序在dialog.setAdapter與nullPointerExeption崩潰。對話框列表適配器在nullPointerExeption崩潰
當用戶點擊listview中的項目時,alertDialog應該彈出。
ArrayAdapter<String> dialogAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, userFunc);
lv.setAdapter(dialogAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(ManagerFunctions.this);
LayoutInflater inflater = getLayoutInflater();
View convertView = (View) inflater.inflate(R.layout.user_op_list, null);
alertDialog.setView(convertView);
alertDialog.setTitle("Choose option");
lv = (ListView) convertView.findViewById(R.id.lv);
alertDialog.show();
這行是一個我在收到錯誤:
lv.setAdapter(dialogAdapter);
哪裏是你的錯誤日誌? – Amy
@RaviRupareliya –
初始化lv – Amy