我正在尝试为AlertDialog
应用自定义视图。我的问题是我使用fragment
,listview
使用了自定义适配器,而alertdialog
我认为它正在使用ViewGroup
混淆了。
这是我对alertdialog
所拥有的东西,但是它一直在崩溃给我一个
适配器视图不支持unsupportedoperationexception addview
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.action_add) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.dialog_new_site, (ViewGroup)getActivity().getCurrentFocus());
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
alertDialogBuilder.setView(dialoglayout);
答案 0 :(得分:0)
试试这个:
View dialoglayout = getActivity().getLayoutInflater().inflate(R.layout.dialog_new_site, null);
答案 1 :(得分:0)
尝试这样做
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
view v = inflater.inflate(R.layout.dialog_layout, null);
答案 2 :(得分:0)
尝试创建自定义警报对话框并使用它。
public class MyAlertDialog extends Dialog {
Context mContext;
public InfoCustomDialog(Context context, int theme) {
super(context, theme);
this.mContext = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_new_site);
}
}
然后使用
MyAlertDialog alertDialog = new MyAlertDialog(getActivity());
alertDialog.show();