ome*_*ega 8 android android-alertdialog
在我的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, fish, image, false, !image.getApproved(), true);
d.dismiss();
} else {
Popup.ShowErrorMessage(GalleryScreen.this, R.string.no_internet, false);
}
}
});
d.show();
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个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)
Run Code Online (Sandbox Code Playgroud)
这是什么意思,我该如何解决?
谢谢.
Lee*_*dev 11
这对我有用
View.inflate(getActivity(), R.layout.dialog, null);
Run Code Online (Sandbox Code Playgroud)
没有任何警告也没有错误.