Hell i am trying to make alert dialogue to show highscore point.but i cant add textview on my dialogue , highscore stores in textview. here is my code i need to show textview when i click NO button.

   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();             
有帮助吗?

解决方案

create xml file 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>

and in java class

{

 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();
 }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top