2014-03-05 28 views
0
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();    
    } 
}); 

任何人都可以幫助我將這個吐司轉換成警報對話框。 請不要降級me..i'm只是一個初學者在機器人..將圖像吐司轉換成圖像AlertDialog

+0

職位的代碼,如果你遇到問題,先試試這個:HTTP:/ /www.mkyong.com/android/android-alert-dialog-example/ – user2450263

+0

夥計們一些**幫助**這** BDY **! –

+0

可能的[如何添加代碼,當文本(textview)被點擊時,會出現一個圖像(功能就像一個警告對話框)的重複。](http://stackoverflow.com/questions/22009511/how-to -put-add-code-that-the-texttextview-is-clicked-an-image-will-appea) – ElDuderino

回答

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(); 
     } 
    }); 
+0

我會在哪裏放置這個。? 這是一張圖片.. imageCodeProject.setImageResource(R.drawable.symptom_muscle_pain); – user3350245

+0

它位於sas3的onClickListener中 –

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(); 
     }