2017-02-25 15 views
-1

私はアンドロイドを初めて使っています。私は小さな基本的なアプリを開発しています。アプリに4つのボタンがあります。ユーザーがボタンを押したときにダイアログが完全に表示されます画面と特定のセットのtext views。例: 私は次のようなボタンがあります: 1)ヒーロー 2)映画。ヒーローボタンを押すとヒーローのリストがムービーと同様に表示されるはずです。私が知っている唯一の方法は、すべてのボタンプレスで新しいアクティビティを作成することです。その代わりに、4つのボタンすべてに対して1つのダイアログを表示する必要があります。これは可能でしょうか?私はこの質問が長く知っているとより良いway.Pleaseに求められることができ、私に何か提案ダイアログとアクティビティ間でデータを渡す

+0

完全な例を参照してくださいは、なぜあなたはそれがダイアログになりたいですか?新しい活動を示すことを最初に考えたような気がします。たぶんあなたはより良い提案を得るためにダイアログが重要である理由を説明することができます。 – seekingStillness

答えて

0

を与えるTextView秒の必要な数を使用したカスタム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" 
    /> 

置き活動でこのshowDialog()方法が

 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(); 
       } 
      }); 
} 

がここhttp://androidexample.com/Custom_Dialog_-_Android_Example/index.php?view=article_discription&aid=88ダイアログをフルスクリーンで表示している場合

関連する問題