在我的
Android应用程序中,我创建了一个这样的对话框:
private void handleEdit() { LayoutInflater inflater = getLayoutInflater(); View dialoglayout = inflater.inflate(R.layout.dialog_gallery,null); final AlertDialog d = new AlertDialog.Builder(this) .setView(dialoglayout) .setTitle(R.string.edit) .setNegativeButton(R.string.cancel,null) .create(); CheckBox mainCB = (CheckBox)dialoglayout.findViewById(R.id.main); CheckBox usedCB = (CheckBox)dialoglayout.findViewById(R.id.used); mainCB.setChecked(image.getIsMain()); usedCB.setChecked(image.getApproved()); mainCB.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (Network.isNetworkAvailable(GalleryScreen.this)) { new Async_update_image_state(GalleryScreen.this,fish,image,!image.getIsMain(),image.getApproved(),false); d.dismiss(); } else { Popup.ShowErrorMessage(GalleryScreen.this,R.string.no_internet,false); } } }); usedCB.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (Network.isNetworkAvailable(GalleryScreen.this)) { new Async_update_image_state(GalleryScreen.this,false,!image.getApproved(),true); d.dismiss(); } else { Popup.ShowErrorMessage(GalleryScreen.this,false); } } }); d.show(); }
但是我在View dialoglayout = inflater.inflate(R.layout.dialog_gallery,null)上收到警告;强调null.
Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout's root element)
这是什么意思,我该如何解决?
谢谢.
解决方法
这对我有用
View.inflate(getActivity(),R.layout.dialog,null);
没有任何警告也没有错误.