2017-02-25 120 views
-1

我是android.I的新手,我正在開發一個小的基本app.I在應用程序中有四個按鈕。我需要的是當用戶按下按鈕時,我想要一個對話框顯示完整屏幕和特定的一組text views。例如: 我有以下按鈕,如: 1)英雄 2)電影。在按英雄按鈕時,英雄列表應該類似地出現在電影中。我知道的唯一方法是爲每個按鈕按下創建一個新的活動。而我想要爲所有四個按鈕顯示單個對話框,但是對話框上顯示的數據應該根據按鈕而變化。這可能嗎?我知道這個問題是漫長的,可能更好way.Please被要求給我任何建議在對話框和活動之間傳遞數據

+0

如果你顯示的對話框全屏完整的例子,爲什麼你希望它是一個對話框?似乎你首先想到展示一項新活動是最好的。也許你可以解釋爲什麼對話是至關重要的,以獲得更好的建議。 – seekingStillness

回答

0

創建與所需數量的TextView S創建自定義Dialog一個方法,並通過您的String值的方法

參考這個例子中

dialog_layout

<ImageView 
    android:id="@+id/imageDialog" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="6dp" /> 

<TextView 
    android:id="@+id/textDialog" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="#FFF" 
    android:layout_toRightOf="@+id/imageDialog"/> 

<Button 
    android:id="@+id/declineButton" 
    android:layout_width="100px" 
    android:layout_height="wrap_content" 
    android:text=" Submit " 
    android:layout_marginTop="5dp" 
    android:layout_marginRight="5dp" 
    android:layout_below="@+id/textDialog" 
    android:layout_toRightOf="@+id/imageDialog" 
    /> 

廣場

 private void showDialog(){ 
      final Dialog dialog = new Dialog(CustomDialog.this); 
      // Include dialog.xml file 
      dialog.setContentView(R.layout.dialog); 
      // Set dialog title 
      dialog.setTitle("Custom Dialog"); 
      // Set Dialog fullscreen 
      dialog.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN); 

      // set values for custom dialog components - text, image and button 
      TextView text = (TextView) dialog.findViewById(R.id.textDialog); 
      text.setText("Custom dialog Android example."); 
      ImageView image = (ImageView) dialog.findViewById(R.id.imageDialog); 
      image.setImageResource(R.drawable.image0); 

      dialog.show(); 

      Button declineButton = (Button) dialog.findViewById(R.id.declineButton); 
      // if decline button is clicked, close the custom dialog 
      declineButton.setOnClickListener(new OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        // Close dialog 
        dialog.dismiss(); 
       } 
      }); 
} 

這種活性showDialog()方法請參考這裏http://androidexample.com/Custom_Dialog_-_Android_Example/index.php?view=article_discription&aid=88

相關問題