将图像转换为图像AlertDialog

时间:2014-03-05 13:23:22

标签: android

sas3.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub"                                                                    "
        Toast toast= Toast.makeText(getApplicationContext(),
                "                                                                    ",
                Toast.LENGTH_SHORT);  
        toast.setGravity(Gravity.CENTER, 0, 0);
        LinearLayout toastView = (LinearLayout) toast.getView();
        ImageView imageCodeProject = new ImageView(getApplicationContext());
        imageCodeProject.setImageResource(R.drawable.symptom_muscle_pain);
        toastView.addView(imageCodeProject, 0);
        toast.show();               
    }
});

任何人都可以帮助我将此吐司转换为警报对话框。?. 请不要降级我..我只是android的初学者..

2 个答案:

答案 0 :(得分:0)

    sas3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // TODO Auto-generated method 
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            this);
            alertDialogBuilder.setTitle("Your Title");
            alertDialogBuilder
            .setMessage("Click yes to exit!")
            .setCancelable(false)
            .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    // if this button is clicked, close
                    // current activity
                    MainActivity.this.finish();
                }
              })
            .setNegativeButton("No",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    // if this button is clicked, just close
                    // the dialog box and do nothing
                    dialog.cancel();
                }
            });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();
        }
    });

答案 1 :(得分:0)

试试这个

AlertDialog.Builder alertDialoBuilder;

    public void getAlertDialog(String title, String message){
            if(alertDialoBuilder!= null)
                alertDialoBuilder= null;

            alertDialoBuilder= new AlertDialog.Builder(this);
            alertDialoBuilder.setTitle(title);
            alertDialoBuilder.setMessage(message);
            alertDialoBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

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

    //you can implement negative button also if you need it
            alertDialoBuilder.create().show();
        }