2014-04-24 106 views
-2

地獄我試圖讓alert對話顯示高分point.but我無法在我的對話,textview高分商店添加textview。這裏是我的代碼,當我點擊NO按鈕時,我需要顯示textview。如何在警報對話框中顯示textview

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
        context); 

       // set title 
       alertDialogBuilder.setTitle("Your Title"); 

       // set dialog message 
       alertDialogBuilder 
        .setMessage("Time is up!") 
        .setCancelable(false) 
        .setPositiveButton("Restart!",new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog,int id) { 
          // if this button is clicked, close 
          // current activity 
          App2Activity.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(); 






     } 
    }.start();    
+0

哪裏是你的TextView locatied? –

+0

final TextView score =(TextView)findViewById(R.id.textscore); \t \t \t \t score.setText(「」+ counter); – Boldbayar

回答

2

創建XML文件dialog_layout_pro.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
    android:background="#dedede" 
    > 
    <TextView 
android:id="@+id/tv_dialog" 
android:layout_margin="30dip" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_centerHorizontal="true" 
android:layout_centerVertical="true" 
android:gravity="center" 
android:textColor="#444444" 
android:text="Please wait..." 
android:textSize="30sp" /> 
</RelativeLayout> 

和Java類

{ 

Dialog cusDialog; 
cusDialog = new Dialog(MyTestClass.this, R.style.CustomDialog); 
cusDialog.setContentView(R.layout.dialog_layout_pro); 
    TextView text = (TextView) cusDialog.findViewById(R.id.tv_dialog); 
    text.setText("here your counter value"); 

cusDialog.setCancelable(false); 
cusDialog.show(); 
}