3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
AlertDialog 複數對話窗呼叫就是在初始對話窗內的按鈕按下後呼叫另一個對話窗出來 兩對話窗就可以交互切換使用,可用於放置不同的資料或圖片之類的訊息 如下圖所示 要達到此效果只要在對話窗裡面互相調用Code即可 示範 XML xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <Button android:id="@+id/btn_Click" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="btn_Click" android:text="Dialog" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> android.support.constraint.ConstraintLayout> JAVA public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void btn_Click(View v){ new AlertDialog.Builder(this) .setTitle("視窗1") .setNegativeButton("2", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { screen2(); } }) .setPositiveButton("OK", null).show(); } private void screen2() { new AlertDialog.Builder(this) .setTitle("視窗2") .setNegativeButton("1", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { screen(); } }) .setPositiveButton("OK", null).show(); } private void screen() { new AlertDialog.Builder(this) .setTitle("視窗1") .setNegativeButton("2", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { screen2(); } }) .setPositiveButton("OK", null).show(); } } 注意screen()的Code務必和btn_Click()裡面的Code保持一致性  

本文由kk665403pixnetnetblog提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦