我正在嘗試修改對話框的佈局,然後執行一些功能並在我的功能結束時關閉警告框。從另一個函數關閉自定義對話框
佈局文件
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:layout_below="@+id/header"
android:paddingTop="15dp"
android:paddingBottom="15dp">
<ImageView
android:id="@+id/cam"
android:layout_width="0dp"
android:layout_height="match_parent"
android:padding="10dp"
android:paddingLeft="10dp"
android:src="@drawable/ic_cam"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:onClick="camera_listener"
/>
<ImageView
android:id="@+id/gal"
android:layout_width="0dp"
android:layout_height="match_parent"
android:padding="10dp"
android:paddingLeft="10dp"
android:src="@drawable/ic_gal"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:onClick="gallery_listener"
/>
</LinearLayout>
Java文件
AlertDialog.Builder myAlertDialog; // Variable declared as a class member
private void startDialog() {
LayoutInflater inflater = this.getLayoutInflater();
final View view = inflater.inflate(R.layout.activity_fab, null);
myAlertDialog = new AlertDialog.Builder(this);
myAlertDialog.show();
}
public void gallery_listener(View view) {
pictureActionIntent = new Intent(Intent.ACTION_PICK, null);
pictureActionIntent.setType("image/*");
pictureActionIntent.putExtra("return-data", true);
startActivityForResult(pictureActionIntent, GALLERY_PICTURE);
myAlertDialog.setOnDismissListener();
}
public void camera_listener(View view) {
pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(pictureActionIntent, CAMERA_REQUEST);
}
我在顯示對話框和定義功能兩幅圖像上的點擊...我想關閉該對話框,儘快執行相應的功能。
我試過使用解僱,但它不工作..!
使用myAlertDialog.dismiss時會出現什麼錯誤? –