Android-シーケンシャル/ネストされたダイアログボックス、2番目のダイアログボックスは最初のダイアログボックスを閉じます

一口

ボタンを押すとリストを含むダイアログボックスが表示され、リスト内の特定の項目を選択すると、番号ピッカーダイアログが表示されるアプリケーションがあります。ユーザーが番号ピッカーダイアログから番号を選択すると、番号ピッカーダイアログのみが閉じ、ダイアログボックスは表示されたままになります。

これはこれまでの私のコードです。

これは、最初のダイアログボックス(リストのあるダイアログボックス)のコードです。

private void generateUnitDialog(String[] productUnit) {

    final CharSequence[] items = productUnit;

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Make your selection");

    builder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // Handle Confirm action here
        }
    });

    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // Handle cancel action here
        }
    });
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            // Do something with the selection
            Toast.makeText(getApplicationContext(),
                    "Item Click detected", Toast.LENGTH_SHORT)
                    .show();

            generateQuantityDialog();

        }
    });

    builder.setCancelable(false);

    AlertDialog alert = builder.create();
    alert.show();

}

特定のリスト項目を選択すると、次のコードを使用してナンバーピッカーダイアログがポップアップ表示されます。

public int generateQuantityDialog(){

         final Dialog d = new Dialog(com.angelo.orderform.OrderForm.this);

         d.setTitle("Choose Quantity");
         d.setContentView(R.layout.dialog);

         Button b1 = (Button) d.findViewById(R.id.button1);
         Button b2 = (Button) d.findViewById(R.id.button2);

         final NumberPicker np = (NumberPicker) d.findViewById(R.id.numberPicker1);

         np.setMaxValue(100000);
         np.setMinValue(1);
         np.setWrapSelectorWheel(true);
         //np.setOnValueChangedListener(this);

         b1.setOnClickListener(new OnClickListener(){
             @Override
             public void onClick(View v) {
                 //tv.setText(String.valueOf(np.getValue()));
                 d.dismiss();
             }    
        });
        b2.setOnClickListener(new OnClickListener(){
          @Override
          public void onClick(View v) {
              d.dismiss();
           }    
          });
       d.show();

       return(np.getValue());


}

ユーザーが特定の番号を選択すると、番号ピッカーダイアログとリストのダイアログが閉じます。リストとのダイアログを表示したままにします。

どうやら、setCancellable(false)は役に立ちません。

何か案は?別のアプローチでも、私は耳を傾けています。

一口

わかりましたが、悪い習慣だと思います。

私がしたことは、番号ピッカーダイアログを生成するコードを配置し、それをgenerateQuantityDialog()元の場所に配置し、builder.show()その後に呼び出したところd.dismiss()です。

このアプローチを捨てて、回避策を探します。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ