我在布局中使用带有自定义适配器的 ListView 。 现在我正在尝试将包含列表的布局带到我的警报对话框中。 我尝试使用此代码将不包含列表的简单布局带到警报对话框中,并且效果很好。 但是我无法将包含布局的列表带入警报对话框。
AlertDialog.Builder dialog = new AlertDialog.Builder( this );
dialog.setView( getLayoutInflater().inflate( R.layout.smill, null ) );
dialog.setIcon(R.drawable.androidsmile);
dialog.setInverseBackgroundForced(true);
dialog.setTitle( "Select smiley");
dialog.setPositiveButton( "Cancel", null );
dialog.show();
最佳答案
您所做的只是将 View 填充到警报对话框中。您没有在该 ListView 上设置适配器,因此它当然会看起来无法正常工作(因为它是空的)。
你需要做类似的事情:
View view = getLayoutInflater().inflate( R.layout.smill, null);
ListView listView = (ListView) view.findViewById(R.id.listView);
YourCustomAdapter adapter = new YourCustomAdapter(parameters...);
listView.setAdapter(adapter);
AlertDialog.Builder dialog = new AlertDialog.Builder( this );
dialog.setView(view);
...
...
...
dialog.show();
关于android - 如何在警报对话框中扩充包含 ListView 的布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7763506/