我在布局中使用带有自定义适配器的列表视图。
现在我试图将包含列表的布局带到我的警报对话框中。
我尝试使用此代码将不包含列表的简单布局引入警报对话框,并且效果良好。
但我无法将包含布局的列表带入警报对话框。
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 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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)