blog

Androidのダイアログの使用例の7つのフォーム

Androidの開発では、多くの場合、ユーザーに尋ねたり、ユーザーが選択できるようにするなど、Androidのインターフェイス上のいくつかのダイアログボックスをポップアップする必要があります。これらの...

May 25, 2014 · 8 min. read
シェア

Androidの開発では、多くの場合、ユーザーに尋ねたり、ユーザーに選択させるなど、Androidのインターフェイス上でいくつかのダイアログボックスをポップアップ表示する必要があります。これらの機能は、Androidのダイアログボックスと呼ばれ、Androidを使用する過程で、私は要約すると、Androidのダイアログタイプは、7種類にほかなりません、私はそれぞれあなたにこれらの7種類のAndroidダイアログダイアログボックスの使用を紹介し、私はあなたが助けることができることを願っています。

1.一般的なダイアログボックスのスタイルを使用して、間違った操作がないことを確認するためにプロンプトをポップアップするreturnボタンが押されたときに効果があります。

ダイアログボックスを作成するコードは以下の通りです:

       protected void       ダイアログボックス。() {   
 
        アラートダイアログ.Builder     ビルダー = new Builder(      メイン.this);   
 
        ビルダー.setMessage("確認終了?");   
 
         ビルダー.setTitle("ヒント");   
 
         ビルダー.setPositiveButton(" , new OnClickListener() {   
 
     @Override  
 
     public void onClick(DialogInterface       ダイアログボックス。, int which) {   
 
       dialog.dismiss();   
 
      Main.this.finish();   
 
     }   
 
    });   
 
         ビルダー.setNegativeButton(" , new OnClickListener() {   
 
     @Override  
 
      public void onClick(DialogInterface dialog, int which) {   
 
       dialog.dismiss();   
 
     }   
 
    });   
 
     builder.create().show();   
 
    }  

このメソッドは、onKeyDown(int keyCode, KeyEvent event)メソッド内で呼び出します。

  public boolean onKeyDown(int keyCode, KeyEvent event) {   
 
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {   
 
          ダイアログ();   
 
    }   
 
    return false;   
 
  }  

2...つのボタンを追加してダイアログボックスの図を変更しました。

ダイアログを作成するメソッドのコードは以下の通りです:

           Dialog      ダイアログボックス。 = new AlertDialog.Builder(this).setIcon(   
 
               アンドロイド.R.drawable.btn_star).setTitle("環境設定調査").setMessage(   
 
              "あなたはジェット-リーの映画が好きですか?").setPositiveButton("非常によく似ている",   
 
       new OnClickListener() {   
 
        @Override  
 
        public void onClick(DialogInterface dialog, int which) {   
 
         // TODO Auto-generated method stub   
 
                   トースト.makeText(Main.this, "私は本当に彼の映画が好きだ。",   
 
                       トースト.LENGTH_LONG).show();   
 
        }   
 
       }).setNegativeButton("好きではない", new OnClickListener() {   
 
      @Override  
 
      public void onClick(DialogInterface dialog, int which) {   
 
       // TODO Auto-generated method stub   
 
              トースト.makeText(Main.this, "私は彼の映画が好きではない"。,        トースト.LENGTH_LONG)   
 
          .show();   
 
       }   
 
     }).setNeutralButton(" , new OnClickListener() {   
 
      @Override  
 
      public void onClick(DialogInterface dialog, int which) {   
 
       // TODO Auto-generated method stub   
 
       Toast.makeText(Main.this, "好きか嫌いかの話", Toast.LENGTH_LONG)   
 
          .show();   
 
      }   
 
     }).create();   
 
     dialog.show();  

3.メッセージの内容は単純なViewタイプです。

ダイアログ・メソッドを作成するコードは以下の通りです:

 new AlertDialog.Builder(this).setTitle("入力してください").setIcon(   
 
               アンドロイド.R.drawable.ic_dialog_info).setView(   
 
        new EditText(this)).setPositiveButton(" , null)   
 
       .setNegativeButton(" , null).show();  

4.メッセージの内容は、ラジオボックスのセットです。

ダイアログ・メソッドを作成するコードは以下の通りです:

  new AlertDialog.Builder(this).setTitle("チェックボックス").setMultiChoiceItems(   
 
        new String[] { "Item1", "Item2" }, null, null)   
 
       .setPositiveButton(" , null)   
 
       .setNegativeButton(" , null).show();  

5.メッセージの内容は、複数の選択ボックスのセットです。

ダイアログ・メソッドを作成するコードは以下の通りです:

  new AlertDialog.Builder(this).setTitle("ラジオボックス").setIcon(   
 
               アンドロイド.R.drawable.ic_         ダイアログボックス。_info).setSingleChoiceItems(   
 
        new String[] { "Item1", "Item2" }, 0,   
 
        new DialogInterface.OnClickListener() {   
 
         public void onClick(DialogInterface dialog, int which) {   
 
          dialog.dismiss();   
 
         }   
 
      }).setNegativeButton(" , null).show();  

6.情報コンテンツは、単純なリスト項目のセットです。

ダイアログを作成するメソッドのコードは以下の通りです:

new AlertDialog.Builder(this).setTitle("リストボックス").setItems(   
 
        new String[] { "Item1", "Item2" }, null).setNegativeButton(   
 
              "OK "をクリックする, null).show();  

7.メッセージの内容はカスタマイズされたレイアウトです。

ダイアログレイアウトファイルのコードは以下の通りです:

    <?xml version="1.0" encoding="utf-8"?>   
 
     
 
   <LinearLayout xmlns:   アンドロイド="http://..com/apk/res/   アンドロイド"  
 
       アンドロイド:layout_height="wrap_content"      アンドロイド:layout_width="wrap_content"  
 
        アンドロイド:background="#ffffffff"     アンドロイド:orientation="horizontal"  
 
   android:id="@+id/dialog">   
 
    <TextView android:layout_height="wrap_content"  
 
      android:layout_width="wrap_content"  
 
     android:id="@+id/tvname" android:text="姓名:" />   
 
    <EditText android:layout_height="wrap_content"  
 
    android:layout_width="wrap_content" android:id="@+id/etname" android:minWidth="100dip"/>   
 
  </LinearLayout>  

ダイアログ・メソッドを作成するコードは以下の通りです:

  LayoutInflater inflater = getLayoutInflater();   
 
     View layout = inflater.inflate(R.layout.dialog,   
 
       (ViewGroup) findViewById(R.id.dialog));   
 
     new AlertDialog.Builder(this).setTitle("カスタムレイアウト").setView(layout)   
 
        .setPositiveButton(" , null)   
 
       .setNegativeButton(" , null).show();  

さて、ここで紹介した方法を使用する上で、Androidのダイアログボックスの上記の7種類は、基本的にすべての完全な、あなたがアンドロイド開発ダイアログの過程で遭遇した場合は、表示するために取り出すことができます。

Read next

マイクロソフト、Windows 8.1の写真機能とBingアプリをアップデートする

Windows 8.1はすでにRTMとなり、一部の顧客にRTMをロールアウトしていますが、マイクロソフトはWindows 8.1のバグ修正、新機能開発、その他の改良にまだ取り組んでいるとのことです。10月17日と18日の正式リリースに先立ち、マイクロソフトはすでにWindows 8.1に内蔵されているBing検索やアプリ、カメラアプリを含む多くのサービスやアプリのアップデートを開発中です。

May 24, 2014 · 1 min read