当我显示对话框,然后我dismis,我再次显示对话框,对话框错误,imganhsp == null。如何修复它们!谢谢
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_margin="5dp"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/anhsp"
android:gravity="center_vertical"
android:src="@drawable/imageadd"
android:layout_width="150dp"
android:layout_height="150dp" />
<EditText
android:id="@+id/edtTen"
android:hint="Tên sản phẩm"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/edtMota"
android:hint="Mô tả sản phẩm"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/edtgia"
android:inputType="number"
android:hint="Giá sản phẩm"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/buttonHuy"
android:text="Hủy"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<Button
android:id="@+id/buttonXacNhan"
android:text="Xác nhận thêm"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.asus.banhangonline.FragmentUngDung.FragmentTabHost.FraAlbum"
android:id="@+id/fragment"
tools:layout="@layout/layout_album" />
</LinearLayout>
&#13;
我的代码:
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (view != null) {
parent = (ViewGroup) view.getParent();
if (parent != null) {
parent.removeView(view);
}
}
try {
view = inflater.inflate(R.layout.dialogfrg_themsp, container, false);
} catch (InflateException e) {
}
AnhXa();
return view;
}
private void AnhXa() {
imganhsp = (ImageView) view.findViewById(R.id.anhsp); // <--- null
btnHuy = (Button) view.findViewById(R.id.buttonHuy);
btnXacNhan = (Button) view.findViewById(R.id.buttonXacNhan);
edtten = (EditText) view.findViewById(R.id.edtTen);
edtmota = (EditText) view.findViewById(R.id.edtMota);
edtgia = (EditText) view.findViewById(R.id.edtgia);
}
当我显示对话框,然后我dismis,我再次显示对话框,对话框错误,imganhsp == null。