In meiner android app, erstelle ich einen Dialog wie folgt aus:Wie behebt man "Vermeiden Sie Null als View-Root" in 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();
}
Aber ich erhalte eine Warnung auf View dialoglayout = inflater.inflate(R.layout.dialog_gallery, null);
die null
unterstreicht.
Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout's root element)
Was bedeutet das und wie kann ich es beheben?
Danke.
http://stackoverflow.com/questions/24832497/avoid-passing-null-as-the-view-root-need-to-resolve-layout-parameters-on-the-in –
http: // stackoverflow .com/questions/26404951/move-passing-null-als-die-ansicht-root-warning-wenn-aufblasen-view-for-use-by-ale –
In diesem Fall ist es OK, Null zu übergeben. Fügen Sie eine Annotation "@ SuppressLint" hinzu, damit Sie nicht belästigt werden. –