Example usage for android.app AlertDialog findViewById

List of usage examples for android.app AlertDialog findViewById

Introduction

In this page you can find the example usage for android.app AlertDialog findViewById.

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID or null if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via #show() or #create() ).

Usage

From source file:com.matthewmitchell.peercoin_android_wallet.ui.WalletActivity.java

private void prepareRestoreWalletDialog(final Dialog dialog) {
    final AlertDialog alertDialog = (AlertDialog) dialog;

    final List<File> files = new LinkedList<File>();

    // external storage
    if (Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.exists()
            && Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.isDirectory())
        for (final File file : Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.listFiles()) {

            if (!file.getName().contains("evergreencoin"))
                continue;

            if (WalletUtils.BACKUP_FILE_FILTER.accept(file) || WalletUtils.KEYS_FILE_FILTER.accept(file)
                    || Crypto.OPENSSL_FILE_FILTER.accept(file))
                files.add(file);/*from  w ww. jav  a2s . c om*/
        }

    // internal storage
    for (final String filename : fileList())
        if (filename.startsWith(Constants.Files.WALLET_KEY_BACKUP_PROTOBUF + '.'))
            files.add(new File(getFilesDir(), filename));

    // sort
    Collections.sort(files, new Comparator<File>() {
        @Override
        public int compare(final File lhs, final File rhs) {
            return lhs.getName().compareToIgnoreCase(rhs.getName());
        }
    });

    final View replaceWarningView = alertDialog
            .findViewById(R.id.restore_wallet_from_storage_dialog_replace_warning);
    final boolean hasCoins = application.getWallet().getBalance(BalanceType.ESTIMATED).signum() > 0;
    replaceWarningView.setVisibility(hasCoins ? View.VISIBLE : View.GONE);

    final Spinner fileView = (Spinner) alertDialog.findViewById(R.id.import_keys_from_storage_file);
    final FileAdapter adapter = (FileAdapter) fileView.getAdapter();
    adapter.setFiles(files);
    fileView.setEnabled(!adapter.isEmpty());

    final EditText passwordView = (EditText) alertDialog.findViewById(R.id.import_keys_from_storage_password);
    passwordView.setText(null);

    final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener(
            passwordView, alertDialog) {
        @Override
        protected boolean hasFile() {
            return fileView.getSelectedItem() != null;
        }

        @Override
        protected boolean needsPassword() {
            final File selectedFile = (File) fileView.getSelectedItem();
            return selectedFile != null ? Crypto.OPENSSL_FILE_FILTER.accept(selectedFile) : false;
        }
    };
    passwordView.addTextChangedListener(dialogButtonEnabler);
    fileView.setOnItemSelectedListener(dialogButtonEnabler);

    final CheckBox showView = (CheckBox) alertDialog.findViewById(R.id.import_keys_from_storage_show);
    showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(passwordView));
}

From source file:de.schildbach.wallet.ui.WalletActivity.java

private void prepareRestoreWalletDialog(final Dialog dialog) {
    final AlertDialog alertDialog = (AlertDialog) dialog;

    final String path;
    final String backupPath = Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.getAbsolutePath();
    final String storagePath = Constants.Files.EXTERNAL_STORAGE_DIR.getAbsolutePath();
    if (backupPath.startsWith(storagePath))
        path = backupPath.substring(storagePath.length());
    else//ww w  .  ja  va  2 s  .c  o  m
        path = backupPath;

    final List<File> files = new LinkedList<File>();

    // external storage
    final File[] externalFiles = Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.listFiles();
    if (externalFiles != null)
        for (final File file : externalFiles)
            if (Crypto.OPENSSL_FILE_FILTER.accept(file))
                files.add(file);

    // internal storage
    for (final String filename : fileList())
        if (filename.startsWith(Constants.Files.WALLET_KEY_BACKUP_PROTOBUF + '.'))
            files.add(new File(getFilesDir(), filename));

    // sort
    Collections.sort(files, new Comparator<File>() {
        @Override
        public int compare(final File lhs, final File rhs) {
            return lhs.getName().compareToIgnoreCase(rhs.getName());
        }
    });

    final TextView messageView = (TextView) alertDialog.findViewById(R.id.restore_wallet_dialog_message);
    messageView.setText(getString(!files.isEmpty() ? R.string.import_keys_dialog_message
            : R.string.restore_wallet_dialog_message_empty, path));

    final Spinner fileView = (Spinner) alertDialog.findViewById(R.id.import_keys_from_storage_file);
    fileView.setVisibility(!files.isEmpty() ? View.VISIBLE : View.GONE);
    final FileAdapter adapter = (FileAdapter) fileView.getAdapter();
    adapter.setFiles(files);

    final EditText passwordView = (EditText) alertDialog.findViewById(R.id.import_keys_from_storage_password);
    passwordView.setVisibility(!files.isEmpty() ? View.VISIBLE : View.GONE);
    passwordView.setText(null);

    final CheckBox showView = (CheckBox) alertDialog.findViewById(R.id.import_keys_from_storage_show);
    showView.setVisibility(!files.isEmpty() ? View.VISIBLE : View.GONE);
    showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(passwordView));

    final View replaceWarningView = alertDialog
            .findViewById(R.id.restore_wallet_from_storage_dialog_replace_warning);
    final boolean hasCoins = wallet.getBalance(BalanceType.ESTIMATED).signum() > 0;
    replaceWarningView.setVisibility(hasCoins ? View.VISIBLE : View.GONE);

    final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener(
            passwordView, alertDialog) {
        @Override
        protected boolean hasFile() {
            return fileView.getSelectedItem() != null;
        }

        @Override
        protected boolean needsPassword() {
            final File selectedFile = (File) fileView.getSelectedItem();
            return selectedFile != null ? Crypto.OPENSSL_FILE_FILTER.accept(selectedFile) : false;
        }
    };
    passwordView.addTextChangedListener(dialogButtonEnabler);
    fileView.setOnItemSelectedListener(dialogButtonEnabler);
}

From source file:com.mantz_it.rfanalyzer.MainActivity.java

public void showInfoDialog() {
    AlertDialog dialog = new AlertDialog.Builder(this)
            .setTitle(Html.fromHtml(getString(R.string.info_title, versionName)))
            .setMessage(Html.fromHtml(getString(R.string.info_msg_body)))
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing
                }//from   w ww  . j  av a  2 s. co m
            }).create();
    dialog.show();

    // make links clickable:
    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:org.smilec.smile.student.CourseList.java

private void removeimage_dialog() {

    chkimg = 0;//from w w  w .j  a  v a  2 s.c om
    activity = this;
    Builder adb = new AlertDialog.Builder(activity);

    adb.setTitle(getString(R.string.rmv_img_dialog_title));
    adb.setMessage(getString(R.string.rmv_img_q));

    adb.setPositiveButton(getString(R.string.OK), new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface arg0, int arg1) {

            bmImg = null;
            imageview.setImageBitmap(bmImg);
            _bmImg = bmImg;
        }

    });

    adb.setNegativeButton(getString(R.string.Cancel), null);
    AlertDialog d = adb.show();
    smile.overrideFonts(activity, d.findViewById(android.R.id.content));
}

From source file:com.hivewallet.androidclient.wallet.ui.WalletActivity.java

private void prepareImportKeysDialog(final Dialog dialog) {
    final AlertDialog alertDialog = (AlertDialog) dialog;

    final List<File> files = new LinkedList<File>();

    // result of ACTION_PICk
    File selectedExternalWalletBackup = new File(getFilesDir(), Constants.Files.EXTERNAL_WALLET_TMP_FILE);
    if (selectedExternalWalletBackup.exists())
        files.add(selectedExternalWalletBackup);

    // local copies of external backups
    File externalWalletBackupDir = new File(getFilesDir(), Constants.Files.EXTERNAL_WALLET_BACKUP_DIR);
    if (externalWalletBackupDir.exists() && externalWalletBackupDir.isDirectory())
        for (final File file : externalWalletBackupDir.listFiles())
            if (WalletUtils.BACKUP_FILE_FILTER.accept(file) || WalletUtils.KEYS_FILE_FILTER.accept(file)
                    || Crypto.OPENSSL_FILE_FILTER.accept(file))
                files.add(file);//from   ww w .j a v a 2  s .c  o m

    // internal storage
    for (final String filename : fileList())
        if (filename.startsWith(Constants.Files.WALLET_KEY_BACKUP_PROTOBUF + '.'))
            files.add(new File(getFilesDir(), filename));

    // sort
    Collections.sort(files, new Comparator<File>() {
        @Override
        public int compare(final File lhs, final File rhs) {
            return lhs.getName().compareToIgnoreCase(rhs.getName());
        }
    });

    final View replaceWarningView = alertDialog
            .findViewById(R.id.restore_wallet_from_storage_dialog_replace_warning);
    final boolean hasCoins = wallet.getBalance(BalanceType.ESTIMATED).signum() > 0;
    replaceWarningView.setVisibility(hasCoins ? View.VISIBLE : View.GONE);

    final Spinner fileView = (Spinner) alertDialog.findViewById(R.id.import_keys_from_storage_file);
    final FileAdapter adapter = (FileAdapter) fileView.getAdapter();
    adapter.setFiles(files);
    fileView.setEnabled(!adapter.isEmpty());

    final EditText passwordView = (EditText) alertDialog.findViewById(R.id.import_keys_from_storage_password);
    passwordView.setText(null);

    final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener(
            passwordView, alertDialog) {
        @Override
        protected boolean hasFile() {
            return fileView.getSelectedItem() != null;
        }

        @Override
        protected boolean needsPassword() {
            final File selectedFile = (File) fileView.getSelectedItem();
            return selectedFile != null ? Crypto.OPENSSL_FILE_FILTER.accept(selectedFile) : false;
        }
    };
    passwordView.addTextChangedListener(dialogButtonEnabler);
    fileView.setOnItemSelectedListener(dialogButtonEnabler);

    final CheckBox showView = (CheckBox) alertDialog.findViewById(R.id.import_keys_from_storage_show);
    showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(passwordView));
}

From source file:org.smilec.smile.student.CourseList.java

private void show_detail(Vector<Integer> _myscore, int num) {

    curcategory = category_arr[2];/*from   ww  w .  j  ava  2  s .  c o  m*/
    scene_number = num;
    setContentView(R.layout.detailresult);

    setTitle(curcategory + "     " + num + "/" + LAST_SCENE_NUM);
    curwebview = (WebView) findViewById(R.id.webviewdetailresult);
    curwebview.clearCache(false);
    setWebviewFontSize(curwebview);

    my_answer_view = (TextView) findViewById(R.id.textresult02);

    ratingbar = (RatingBar) findViewById(R.id.ratingbar);

    showScene();

    Button returnMR = (Button) findViewById(R.id.returnresult02);
    returnMR.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            seeResults();
        }
    });

    Button prevDR = (Button) findViewById(R.id.prevResult);
    prevDR.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            if (scene_number > 1) {
                showPreviousScene();
            }
        }
    });

    Button nextDR = (Button) findViewById(R.id.nextResult);
    nextDR.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            if (scene_number != LAST_SCENE_NUM) {
                showNextScene();
            } else {

                Builder adb = new AlertDialog.Builder(CourseList.this);
                adb.setTitle(curcategory);
                adb.setMessage(getString(R.string.notice_last_q));
                adb.setPositiveButton(getString(R.string.OK), null);
                AlertDialog d = adb.show();
                smile.overrideFonts(activity, d.findViewById(android.R.id.content));
            }
        }
    });

}

From source file:org.smilec.smile.student.CourseList.java

private void show_todo_view() {

    //setTitle(APP_TAG + " - " + curusername);   
    setAppTitle(WIFI_CONNECTED);/* w w  w .  j  a v  a 2s .  com*/
    setContentView(R.layout.category);

    inform = (TextView) findViewById(R.id.ProgressText);

    makeQ = (Button) findViewById(R.id.MKQbutton);
    solveQ = (Button) findViewById(R.id.SOLQbutton);
    seeR = (Button) findViewById(R.id.SEERbutton);
    exitTodoView = (Button) findViewById(R.id.exitbutton);

    makeQ.setText(category_arr[0]);
    solveQ.setText(category_arr[1]);
    seeR.setText(category_arr[2]);
    exitTodoView.setText(R.string.category_exit);

    makeQ.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            change_todo_view_state(WAIT_SOLVE_QUESTION);
            student.can_rest_now();
            MakeQuestion();

        }
    });
    solveQ.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            change_todo_view_state(WAIT_SEE_RESULT);
            student.can_rest_now();
            SolveQuestion();
            selarridx = 0;
        }
    });

    seeR.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            change_todo_view_state(FINISH);
            // comment out for re-take the quiz and start a new session
            // student.can_rest_now();   
            seeResults();
            selarridx = 1;
        }
    });

    exitTodoView.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {

            final Builder adb = new AlertDialog.Builder(CourseList.this);

            adb.setTitle(getString(R.string.warn));
            adb.setMessage(getString(R.string.exit_q));
            adb.setPositiveButton(getString(R.string.OK), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    CourseList.this.finish();
                }
            });

            adb.setNegativeButton(getString(R.string.Cancel), null);
            AlertDialog d = adb.show();
            smile.overrideFonts(activity, d.findViewById(android.R.id.content));
        }
    });

    change_todo_view_state(this.last_state_received); // init_state
}

From source file:org.smilec.smile.student.CourseList.java

private void SolveQuestion() {

    SolvingIndex = false;/* w  w  w .j ava2s. com*/
    issolvequestion = 0;
    // 1st screen
    curwebview = webviewQ;
    curcategory = category_arr[1];
    scene_number = 1;

    setTitle(curcategory + "   1/" + LAST_SCENE_NUM);
    setContentView(R.layout.question);

    curwebview = (WebView) findViewById(R.id.webviewQ);
    rgb02 = (RadioGroup) findViewById(R.id.rgroup02);
    rgb03 = (RadioGroup) findViewById(R.id.rgroup03);
    ratingbar = (RatingBar) findViewById(R.id.ratingbarQ);
    curwebview.clearCache(true);

    setWebviewFontSize(curwebview);

    // zoom
    //curwebview.getSettings().setBuiltInZoomControls(true);
    /*
    zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
    zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
     public void onClick(View v) {
    curwebview.zoomIn();
     }
    });
    zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
             
     public void onClick(View v) {
    curwebview.zoomOut();
     }
    });
    zoomControls.hide();
    *//*
       final GestureDetector gestureDetector = new GestureDetector(getApplicationContext(), new GestureDetector.SimpleOnGestureListener() {
         @Override
         public boolean onDoubleTap(MotionEvent e) {
         String url = curwebview.getUrl();
          Log.d("**APP**", "Double Tap event url:"+url);
          if (curwebview!=null && curwebview.canGoBack() && url.endsWith(".jpg")) 
         {
             //zoomControls.hide();
            curwebview.goBack();
         }
                     
          return false;              
         }
               
         @Override
         public boolean onDown(MotionEvent e) {
         String url = curwebview.getUrl();
          Log.d("**APP**", "onDown event url:"+url);
          if (curwebview!=null && url.endsWith(".jpg")) 
         {
             //zoomControls.show();
         }
          return false;
         }
       });
       gestureDetector.setIsLongpressEnabled(true);
               
       curwebview.setOnTouchListener(new OnTouchListener(){
                
         public boolean onTouch(View v, MotionEvent event) {
          return gestureDetector.onTouchEvent(event);
         }
               
       });*/
    // zoom

    getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);

    curwebview.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            // Make the bar disappear after URL is loaded, and changes
            // string to Loading...
            CourseList.this.setTitle(getString(R.string.loading));
            CourseList.this.setProgress(progress * 100); // Make the bar
            // disappear
            // after URL is
            // loaded
            // Restore the app name after finish loading
            if (progress == 100)
                CourseList.this.setTitle(curcategory + "   " + scene_number + " /" + LAST_SCENE_NUM);
        }
    });

    initialize_AnswerRatingArray_withDummyValues();

    showScene();

    checkCurrentAnswers();

    // reset button (delete previous answer)
    Button resetB = (Button) findViewById(R.id.resetQ);
    resetB.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            rgb02.clearCheck();
            //rgb03.clearCheck();
            ratingbar.setRating(new Float(0));
        }
    });

    // previous button
    Button prevB = (Button) findViewById(R.id.prevQ);
    prevB.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            if (scene_number > 1) {

                int temp = saveCurrentAnswers();
                showPreviousScene();
                checkCurrentAnswers();
            }
        }
    });

    // next button
    Button nextB = (Button) findViewById(R.id.nextQ);
    nextB.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            if (scene_number != LAST_SCENE_NUM) {

                int temp1 = saveCurrentAnswers();
                if (temp1 == 2) {
                    showNextScene();
                    checkCurrentAnswers();
                } else {
                    //Toast.makeText(CourseList.this,getString(R.string.insert_error), Toast.LENGTH_SHORT).show();
                    showToast(getString(R.string.insert_error));
                }

            } else {

                int temp1 = saveCurrentAnswers(); // save the last answer

                if (temp1 == 2) {
                    Builder adb = new AlertDialog.Builder(CourseList.this);
                    adb.setTitle(curcategory);
                    adb.setMessage(getString(R.string.submit_q));
                    adb.setPositiveButton(getString(R.string.submit_btn),
                            new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface arg0, int arg1) {

                                    student.submit_answer_to_teacher(answer_arr, rating_arr);

                                    // Log.d(APP_TAG,
                                    // "answer_arr[0]="+answer_arr.get(0));
                                    // Log.d(APP_TAG,
                                    // "answer_arr[1]="+answer_arr.get(1));

                                    show_todo_view();
                                    selarridx = 0;
                                    SolvingIndex = true;

                                }
                            });

                    adb.setNegativeButton(getString(R.string.Cancel), null);
                    AlertDialog d = adb.show();
                    smile.overrideFonts(activity, d.findViewById(android.R.id.content));
                } else {
                    /*Toast.makeText(CourseList.this,
                          getString(R.string.insert_error), Toast.LENGTH_SHORT)
                          .show();*/
                    showToast(getString(R.string.insert_error));
                }
            }
        }
    });

}

From source file:no.barentswatch.fiskinfo.BaseActivity.java

public void createConfirmLogoutDialog(Context activityContext, int rPathToTitleOfPopup,
        int rPathToTextInTheBodyOfThePopup) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activityContext);
    AlertDialog dialog;
    builder.setTitle(rPathToTitleOfPopup);
    builder.setMessage(rPathToTextInTheBodyOfThePopup);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override//from   w ww  .ja  v a  2  s  .  c  o  m
        public void onClick(DialogInterface dialog, int which) {
            invalidateAuthenticationData();
            dialog.dismiss();
            loadView(MainActivity.class);
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    dialog = builder.create();
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            actionBar.setSelectedNavigationItem(adapter.getCount());
        }
    });

    dialog.show();
    dialog.setCanceledOnTouchOutside(false);

    TextView messageView = (TextView) dialog.findViewById(android.R.id.message);
    messageView.setGravity(Gravity.CENTER);
}

From source file:org.smilec.smile.student.CourseList.java

void MakeQuestion() {

    curcategory = category_arr[0];/*from   ww  w .j  av  a  2  s  .c o  m*/

    setTitle(curcategory);
    setContentView(R.layout.mkquestion);

    imageview = (ImageView) findViewById(R.id.galleryimg01);

    final EditText myContent = (EditText) findViewById(R.id.mkqContent);
    final EditText myOp1 = (EditText) findViewById(R.id.op1);
    final EditText myOp2 = (EditText) findViewById(R.id.op2);
    final EditText myOp3 = (EditText) findViewById(R.id.op3);
    final EditText myOp4 = (EditText) findViewById(R.id.op4);
    rgb04 = (RadioGroup) findViewById(R.id.rgroup04); // for inserting right answer

    // if (galleryidx == 1) SaveImage();

    // retain the previous contents for preview
    if ((previewidx == 1) || (galleryidx == 1)) {

        galleryidx = 0;

        myContent.setText(question_arr[0]);
        myOp1.setText(question_arr[1]);
        myOp2.setText(question_arr[2]);
        myOp3.setText(question_arr[3]);
        myOp4.setText(question_arr[4]);
        if (question_arr[5] != null && question_arr[5] != "")
            rgb04.check(Integer.parseInt(question_arr[5]) + R.id.rightan01 - 1);
        imageview.setImageBitmap(_bmImg);
    }

    // Add Image
    ImageButton addimg = (ImageButton) findViewById(R.id.camera01);
    addimg.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {

            // retain the previous information
            int checked_rid = rgb04.getCheckedRadioButtonId();
            int my_an = checked_rid - R.id.rightan01 + 1;

            myRightan = Integer.toString(my_an);

            String _content = myContent.getText().toString();
            String _op1 = myOp1.getText().toString();
            String _op2 = myOp2.getText().toString();
            String _op3 = myOp3.getText().toString();
            String _op4 = myOp4.getText().toString();
            String _rightan = myRightan;
            question_arr[0] = _content;
            question_arr[1] = _op1;
            question_arr[2] = _op2;
            question_arr[3] = _op3;
            question_arr[4] = _op4;
            question_arr[5] = _rightan;
            //----------------------------------------------------------

            image_qa = new QuickAction(v);

            image_qa.addActionItem(image_first);
            image_qa.addActionItem(image_second);
            image_qa.addActionItem(image_third);

            image_qa.show();
        }

    });

    // save a question made by student (ok = 1, cancel = 2, post+makeQuestion = 3)
    Button post1 = (Button) findViewById(R.id.post01);
    post1.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {

            final Builder adb = new AlertDialog.Builder(CourseList.this);
            adb.setTitle(curcategory);
            adb.setMessage(getString(R.string.post_q));
            adb.setPositiveButton(getString(R.string.OK), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface arg0, int arg1) {

                    int checked_rid = rgb04.getCheckedRadioButtonId();
                    int my_an = checked_rid - R.id.rightan01 + 1;

                    if (my_an < 0) {
                        /*Toast.makeText(CourseList.this,
                         getString(R.string.error_noanswer),
                         Toast.LENGTH_SHORT).show();*/
                        showToast(getString(R.string.error_noanswer));
                    } else {

                        myRightan = Integer.toString(my_an);

                        if (bmImg != null) {
                            ByteArrayOutputStream jpg = new ByteArrayOutputStream(64 * 1024);
                            boolean error = bmImg.compress(Bitmap.CompressFormat.JPEG, 100, jpg);

                            if (!error)
                                Log.d(APP_TAG, "ERROR JPEG");

                            // post with picture
                            student.post_question_to_teacher_picture(myContent.getText().toString(),
                                    myOp1.getText().toString(), myOp2.getText().toString(),
                                    myOp3.getText().toString(), myOp4.getText().toString(), myRightan,
                                    jpg.toByteArray());

                        } else { // post it without picture
                            student.post_question_to_teacher(myContent.getText().toString(),
                                    myOp1.getText().toString(), myOp2.getText().toString(),
                                    myOp3.getText().toString(), myOp4.getText().toString(), myRightan);
                        }

                        Log.d(APP_TAG, "Posting:" + myContent.getText().toString());
                        // after posting question, return the main
                        // screen
                        if (previewidx == 1) {
                            previewidx = 0;
                            _bmImg = null;
                        }

                        show_todo_view();
                        selarridx = 0;

                    }
                }
            });

            // Cancel to post the question
            adb.setNegativeButton(getString(R.string.Cancel), null);

            // Post and make the question
            adb.setNeutralButton(getString(R.string.Post_MoreQ), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface arg0, int arg1) {
                    int checked_rid = rgb04.getCheckedRadioButtonId();
                    int my_an = checked_rid - R.id.rightan01 + 1;

                    if (my_an < 0) {
                        /*Toast.makeText(CourseList.this,
                         getString(R.string.error_noanswer),
                         Toast.LENGTH_SHORT).show();*/
                        showToast(getString(R.string.error_noanswer));
                    } else {

                        myRightan = Integer.toString(my_an);

                        if (bmImg != null) {
                            ByteArrayOutputStream jpg = new ByteArrayOutputStream(64 * 1024);
                            boolean error = bmImg.compress(Bitmap.CompressFormat.JPEG, 100, jpg);

                            if (!error)
                                Log.d(APP_TAG, "ERROR JPGE");

                            // post with picture
                            student.post_question_to_teacher_picture(myContent.getText().toString(),
                                    myOp1.getText().toString(), myOp2.getText().toString(),
                                    myOp3.getText().toString(), myOp4.getText().toString(), myRightan,
                                    jpg.toByteArray());

                        } else { // post it without picture
                            student.post_question_to_teacher(myContent.getText().toString(),
                                    myOp1.getText().toString(), myOp2.getText().toString(),
                                    myOp3.getText().toString(), myOp4.getText().toString(), myRightan);
                        }

                        Log.d(APP_TAG, "Posting:" + myContent.getText().toString());

                        if (previewidx == 1) {
                            previewidx = 0;
                            _bmImg = null;
                            chkimg = 0;
                            bmImg = null;
                        }

                        chkimg = 0;
                        selarridx = 0;
                        bmImg = null;
                        MakeQuestion();
                    }
                }
            });

            AlertDialog d = adb.show();
            smile.overrideFonts(activity, d.findViewById(android.R.id.content));
        }
    });

    // Preview the newly created question
    Button preview1 = (Button) findViewById(R.id.preview01);
    preview1.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {

            previewidx = 1;

            int checked_rid = rgb04.getCheckedRadioButtonId();
            int my_an = checked_rid - R.id.rightan01 + 1;

            myRightan = Integer.toString(my_an);

            String _content = myContent.getText().toString();
            String _op1 = myOp1.getText().toString();
            String _op2 = myOp2.getText().toString();
            String _op3 = myOp3.getText().toString();
            String _op4 = myOp4.getText().toString();
            String _rightan = myRightan;

            question_arr[0] = _content;
            question_arr[1] = _op1;
            question_arr[2] = _op2;
            question_arr[3] = _op3;
            question_arr[4] = _op4;
            question_arr[5] = _rightan;

            preview(_content, _op1, _op2, _op3, _op4);

        }
    });

}