如何在Android中没有按下按钮的情况下创建弹出对话框/布局?

时间:2017-08-04 21:00:22

标签: java android android-layout

这是我的代码,在if语句后我想在else语句中显示一个对话框。布局如下。

   else{
                AlertDialog.Builder mBuilder=new     AlertDialog.Builder(IS_Quiz.this);
View mView= LayoutInflater.from(IS_Quiz.this).inflate(R.layout.quiz_dialog,null);
                Button mbutton=(Button) mView.findViewById(R.id.SameSubject);
                Button mbutton2=(Button) mView.findViewById(R.id.AnotherSubject);
                mbutton.setText("Try Another "+subNameQuiz+" Quiz");
                TextView mtext=(TextView)mView.findViewById(R.id.correctcount);
                mtext.setText(mScore);
                TextView mtext1=(TextView)mView.findViewById(R.id.incorrectcount);
                mtext1.setText(incorrect);
                TextView mtext2=(TextView)mView.findViewById(R.id.skippedcount);
                mtext2.setText(skipped);

mBuilder.setView(mView);
                  mBuilder.show();

            }

这是我的IS_QUIZ

的java代码

         

    android:layout_alignRight="@+id/correct"
    android:layout_alignEnd="@+id/correct"
    android:text="0"

    android:textColor="@color/colorPrimary"
    android:textSize="20sp"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    android:text="Skipped:    "
    android:layout_alignParentRight="true"
    android:textSize="20sp"
   android:id="@+id/Skipped"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="0"
    android:layout_marginBottom="20dp"
    android:layout_alignRight="@+id/Skipped"
    android:layout_alignEnd="@+id/Skipped"
    android:textSize="20sp"
    android:id="@+id/skippedcount"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Incorrect:    "
    android:textSize="20sp"
    android:layout_marginBottom="20dp"
    android:textAlignment="center"
    android:id="@+id/incorrect"

    android:layout_centerHorizontal="true"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="0"
    android:layout_marginBottom="20dp"
    android:layout_alignRight="@+id/incorrect"
    android:layout_alignEnd="@+id/incorrect"
    android:textColor="#FF0000"
    android:textSize="20sp"
    android:textAlignment="center"
    android:id="@+id/incorrectcount"

    android:layout_centerHorizontal="true"/>

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
android:layout_below="@+id/correct"
    android:background="#32996c"
    android:text="Try Another Same Subject Quiz"
    android:textColor="#fff"
    android:padding="10dp"
    android:onClick="onClickSame"
    android:layout_marginBottom="10dp"
    android:id="@+id/SameSubject"/>
<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Try Quiz From Another Subject"
      android:layout_below="@+id/SameSubject"
    android:background="#32996c"
    android:textColor="#fff"
    android:padding="10dp"
    android:layout_marginBottom="10dp"
    android:onClick="onClickAnother"
    android:id="@+id/AnotherSubject"/>
<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
        android:text="Go to Home Page"
    android:layout_below="@+id/AnotherSubject"
    android:background="#32996c"
    android:textColor="#fff"
    android:padding="10dp"
    android:onClick="onClickHome"
    android:layout_marginBottom="10dp"
    android:id="@+id/GoHome"/>

如何在Android中没有按下按钮的情况下创建弹出对话框/布局?这是对话框的布局我希望此布局显示为弹出窗口。我希望它能在没有按键的情况下发出其他声明。

0 个答案:

没有答案