Подтвердить что ты не робот

Диалоговое окно с кнопкой и кнопкой подтверждения

enter image description here
Я хочу добавить кнопку, центрированную под двумя радиосвязными переключателями B, и когда я проверил опцию и нажимаю на подтверждение, действие будет выполнено. Любая помощь пожалуйста

final CharSequence[] photo = {"A","B"};

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

alert.setTitle("Select Gender");

alert.setSingleChoiceItems(photo,-1, new 

DialogInterface.OnClickListener()

{

    @Override
    public void onClick(DialogInterface dialog, int which) 
    {
        if(photo[which]=="A")

        {

            gen="B";
        }

        else if (photo[which]=="B")

        {

            gen="B";

        }
    }

});
alert.show();
4b9b3361

Ответ 1

Мой метод создания пользовательского диалога

http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application ссылка здесь

  • Создайте один пользовательский диалог xml

       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    
        <RadioButton
            android:id="@+id/rd_!"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="A" />
    
        <RadioButton
            android:id="@+id/rd_2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/rd_!"
            android:text="B" />
    
        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/rd_2"
            android:layout_centerInParent="true"
            android:text="OK" />
        </RelativeLayout>
    

и файл activity.java

  Dialog dialog = new Dialog(Dialogeshow.this);
    dialog.setContentView(R.layout.custom_dialoge);
    dialog.setTitle("This is my custom dialog box");
    dialog.setCancelable(true);
    // there are a lot of settings, for dialog, check them all out!
    // set up radiobutton
    RadioButton rd1 = (RadioButton) dialog.findViewById(R.id.rd_);
    RadioButton rd2 = (RadioButton) dialog.findViewById(R.id.rd_2);

    // now that the dialog is set up, it time to show it
    dialog.show();

Ответ 2

Попробуйте сделать это, вам просто нужно выбрать выбор по умолчанию и добавить в диалог целое число → inputSelection

final CharSequence[] items = { " HDMI IN ", " AV IN" };

        // Creating and Building the Dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Select Input Type");

        builder.setSingleChoiceItems(items,inputSelection,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {
                        inputSelection = item;
                        levelDialog.dismiss();
                    }
                });
        levelDialog = builder.create();
        levelDialog.show();

Ответ 3

Вы можете использовать метод ниже, чтобы отобразить диалог

public void showDialog(Context context, String title, String[] btnText,
        DialogInterface.OnClickListener listener) {

    final CharSequence[] items = { "One", "Two" };

    if (listener == null)
        listener = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface paramDialogInterface,
                    int paramInt) {
                paramDialogInterface.dismiss();
            }
        };
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title);

    builder.setSingleChoiceItems(items, -1,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {

                }
            });
    builder.setPositiveButton(btnText[0], listener);
    if (btnText.length != 1) {
        builder.setNegativeButton(btnText[1], listener);
    }
    builder.show();
}

И вызывающая часть может быть выполнена следующим образом:

showDialog(MainActivity.this, "Your Title", new String[] { "Ok" },
    new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

            if(which==-1)
            Log.d("Neha", "On button click");
            //Do your functionality here
        }
    });

Ответ 4

Вы можете добавить одну кнопку в свое диалоговое окно, используя Builder.setNeutralButton.