使用此
pglist = (ListView) dialog.findViewById(R.id.lvpg);
pglist = (ListView) findViewById(R.id.lvpg);
另一个问题是,您正在将相同的布局设置为
listview
适配器
自定义对话框
检查一下
试试这个
ArrayAdapter<String> adapter = new ArrayAdapter<>(Gorups.this, android.R.layout.simple_list_item_1, NAMES);
或者试试这个
Dialog dialog=new Dialog(Gorups.this);
dialog.setTitle("Saved Contacts");
dialog.setContentView(R.layout.custome_dialog);
pglist = (ListView) dialog.findViewById(R.id.lvpg);;
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
Gorups.this,
android.R.layout.simple_list_item_1, NAMES );
pglist.setAdapter(arrayAdapter);
dialog.show();
编辑
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ListView
android:id="@+id/lvpg"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>