13

アラート ダイアログ ボックスに 2 つの編集テキスト フィールドを追加したいと考えています。解決策が簡単に聞こえるほど、私はまだ機能するものを集めることができませんでした。2 つの (テキスト編集) ビューを同時に設定できません。

さらにコードを見たい場合はコメントしてください。

                alertDialog.setTitle("Values");
                final EditText quantity = new EditText(SecondScan.this);
                final EditText lot = new EditText(SecondScan.this);

                quantity.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                lot.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

                Project=arr[0].toString();
                Item=arr[1].toString();


                alertDialog.setMessage( "Employee No. : " + (Login.user).trim()+
                        "\nWarehouse      : " + (FirstScan.Warehouse).trim()+ 
                        "\nLocation           : " + (FirstScan.Location).trim()+ 
                        "\nProject              : " + Project.trim() + 
                        "\nItem                   : " + Item.trim() + 
                        "\nLot                      : " + Lot.trim()+  
                        "\n\nQuantity   :" );
                alertDialog.setView(quantity);
                    alertDialog.setView(lot);
 // the bit of code that doesn't seem to be working.


                alertDialog.setCancelable(false);
                alertDialog.setPositiveButton("Update",  new DialogInterface.OnClickListener() { 

                    public void onClick(DialogInterface dialog, int id) {
                        //ACTION
                    }
                });

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

ロットの後に最初の編集テキストを表示し、数量の後に 2 番目の編集テキストを表示したいのですが、両方のビューをプッシュしようとすると、そのうちの 1 つだけが機能しているように見えます。

更新:実際には、レイアウトを作成せずにアラートダイアログボックスに複数のビューを単独で追加する方法はありません。

4

4 に答える 4

10

ログインポップアップに LinearLayout を使用しました。

public final String POPUP_LOGIN_TITLE="Sign In";
public final String POPUP_LOGIN_TEXT="Please fill in your credentials";
public final String EMAIL_HINT="--Email--";
public final String PASSWORD_HINT="--Password--";

AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle(POPUP_LOGIN_TITLE);
        alert.setMessage(POPUP_LOGIN_TEXT);

        // Set an EditText view to get user input 
        final EditText email = new EditText(this);
        email.setHint(EMAIL_HINT);
        final EditText password = new EditText(this);
        password.setHint(PASSWORD_HINT);
        LinearLayout layout = new LinearLayout(getApplicationContext());
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.addView(email);
        layout.addView(password);
        alert.setView(layout);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

          // Do something with value!
          }
        });

        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            // Canceled.
          }
        });

        alert.show();
于 2013-08-11T21:32:46.860 に答える
2

EditTexts を追加できる垂直 LinearLayout を作成する必要があります。次に、 LinearLayout で alertDialog.setView() を使用します。

詳細については、ここを参照してください:カスタム AlertDialog ビューを実装する方法、 またはここで警告ダイアログに 2 つの編集テキスト フィールドを追加する方法

于 2013-04-23T12:53:37.940 に答える
1

完全オーダーメイドのレイアウトを作ってみませんか?

これは、カテゴリのリストを表示し、ユーザーに選択させるために使用するカスタム ポップアップです。

public class CategoryPickerFragment extends DialogFragment implements OnItemClickListener{
private CategoryReceiver receiver;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    View view = inflater.inflate(R.layout.category_picker_fragment, null);

    builder.setView(view);
    AlertDialog ad = builder.create();

    CategoryList categoryList = (CategoryList) view.findViewById(R.id.clCategories);
    categoryList.setOnItemClickListener(this);

    return ad;
}
public void setCategoryReceiver(CategoryReceiver receiver){
    this.receiver = receiver;
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Category category = ((CategoryListChild)view).getCategory();
    receiver.setCategory(category);
    this.dismiss();
}

DialogFragment を拡張し、OnCreateDialog の alertDialog をカスタム レイアウトでオーバーライドしてから、ユーザーに表示することに注意してください。

于 2013-04-23T12:54:48.213 に答える