Custom AlertDialog.Builder正负按钮未显示

问题描述 投票:0回答:1

您好,一旦我展示了RecyclerView,无论如何,我都会遵循Stack Overflow和YouTube中的所有教程,然后我需要毫无问题地完成其他事情。无论如何,我唯一的问题是正按钮和负按钮消失了。我认为问题可能是我在XML中所做的事情与视图中的按钮重叠,但是RecyclerView中只有3个项目,所以这是我的最大疑问。我在onLongClick中创建了对话框,然后添加了RecyclerView方法来获取行中的位置和数据,这就是为什么我不能在另一个地方调用alertDialog.setPositiveButton()的原因。要获得一些帮助,这是一个很大的挑战。

这是我的XML

<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    <TextView
        android:id="@+id/text_adm_asigna_asesor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:fontFamily="@font/poppins_bold"
        android:text="Asigna un asesor"
        android:textColor="@android:color/black"
        android:textSize="18sp"
        android:textStyle="bold" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="30dp"
        android:visibility="visible"
        android:layout_marginRight="30dp" />

        <LinearLayout
            android:id="@+id/linear_dialog_testDrive"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:visibility="gone"
           >

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/circle_imagen_seleccion_alert"
                android:layout_width="70dp"
                android:layout_height="70dp"
                android:visibility="gone"
                android:src="@drawable/lifeon_logo"
                android:layout_marginLeft="40dp">

            </de.hdodenhof.circleimageview.CircleImageView>

            <TextView
                android:id="@+id/alert_cambia_test_drive_nombre"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/poppins_bold"
                android:textColor="@android:color/black"
                android:text="@string/nombre"
                android:visibility="gone"
                android:layout_marginLeft="30dp">

            </TextView>

        </LinearLayout>

        <Button
            android:id="@+id/cambiar_seleccion_alert_test_drive"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:background="@drawable/button_shape"
            android:text="@string/cambiar_seleccion"
            android:layout_gravity="center_horizontal"
            android:visibility="gone"
            >

        </Button>

    </LinearLayout>
    </LinearLayout>

</androidx.core.widget.NestedScrollView>

这是Java代码

      recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), recyclerView, new RecyclerTouchListener.ClickListener() {
        @Override
        public void onClick(View view, int position) {

        }

        @Override
        public void onLongClick(View view, int position) {
            asesores.clear();

            ParseObject itemTestDrive = listadoTestDrive.get(position);

            testDriveObjectId = itemTestDrive.getObjectId();

            LayoutInflater inflater = getLayoutInflater();
            View convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.activity_agreements, null);
            alertDialog.setView(convertView);


            RecyclerView list = convertView.findViewById(R.id.list);
            TextView txt = convertView.findViewById(R.id.text_adm_asigna_asesor);
            CircleImageView ima=convertView.findViewById(R.id.circle_imagen_seleccion_alert);
            TextView txtNombreSeleccion=convertView.findViewById(R.id.alert_cambia_test_drive_nombre);
            Button botonCambiarSeleccion=convertView.findViewById(R.id.cambiar_seleccion_alert_test_drive);
            LinearLayout linearLayout=convertView.findViewById(R.id.linear_dialog_testDrive);


            botonCambiarSeleccion.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    list.setVisibility(View.VISIBLE);
                    ima.setVisibility(View.GONE);
                    txtNombreSeleccion.setVisibility(View.GONE);
                    botonCambiarSeleccion.setVisibility(View.GONE);
                    linearLayout.setVisibility(View.GONE);
                }
            });

            ParseQuery<ParseObject> query1 = ParseQuery.getQuery("CitaTestDrive");
            query1.include("ComercialAsignado");
            query1.getInBackground(testDriveObjectId, new GetCallback<ParseObject>() {
                @Override
                public void done(ParseObject object, ParseException e) {
                    if (object.getParseObject("ComercialAsignado") != null) {
                        txt.setText(getActivity().getResources().getString(R.string.Advertencia_asignacion_a_alguien));

                    }


                }
            });



            ParseUser user = ParseUser.getCurrentUser();

            ParseObject sucursal = user.getParseObject("PerteneceSucursal");
            String sucurObjectId = sucursal.getObjectId();

            ParseQuery<ParseUser> query = ParseUser.getQuery();
            ParseObject suc = ParseObject.createWithoutData("Sucursal", sucurObjectId);
            query.whereEqualTo("PerteneceSucursal", suc);
            query.include("PerteneceSucursal");
            query.whereEqualTo("Rol","Asesor");
            query.findInBackground(new FindCallback<ParseUser>() {
                @Override
                public void done(List<ParseUser> objects, ParseException e) {
                    if (e == null) {
                        for (ParseUser obj : objects) {
                            asesores.add(obj);
                        }
                        list.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
                        list.setHasFixedSize(true);
                        ListAsesorAdminAsignaTestDrive adapter = new ListAsesorAdminAsignaTestDrive(getApplicationContext(), asesores);
                        list.setAdapter(adapter);
                    }
                }
            });
            list.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), list, new RecyclerTouchListener.ClickListener() {
                @Override
                public void onClick(View view, int position) {
                    ParseUser item = asesores.get(position);

                    list.setVisibility(view.GONE);
                    ima.setVisibility(view.VISIBLE);
                    txtNombreSeleccion.setVisibility(view.VISIBLE);
                    botonCambiarSeleccion.setVisibility(View.VISIBLE);
                    linearLayout.setVisibility(View.VISIBLE);


                    ParseFile parseFile = item.getParseFile("Avatar");
                    if (parseFile != null) {
                        parseFile.getDataInBackground(new GetDataCallback() {
                            @Override
                            public void done(byte[] data, ParseException e) {
                                if (e == null) {
                                    Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
                                    if (bmp != null) {
                                        ima.setImageBitmap(bmp);
                                    }
                                }
                            }
                        });
                    }

                    String asesorObjectId = item.getObjectId();
                    String asesorNombre = item.getString("Nombre");
                    txtNombreSeleccion.setText(asesorNombre);


                    alertDialog.setPositiveButton(getApplicationContext().getResources().getString(R.string.guardar), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ParseQuery<ParseObject> query = ParseQuery.getQuery("CitaTestDrive");

                            query.getInBackground(testDriveObjectId, new GetCallback<ParseObject>() {
                                @Override
                                public void done(ParseObject object, ParseException e) {

                                    object.put("ComercialAsignado", ParseObject.createWithoutData("_User", asesorObjectId));
                                    object.put("PendienteAsignacionAdmin", "Asignado");
                                    object.saveInBackground(new SaveCallback() {
                                        @Override
                                        public void done(ParseException e) {
                                            if (e == null) {
                                                Toast.makeText(getApplicationContext(), "Test drive asignado a:" + asesorNombre, Toast.LENGTH_LONG).show();
                                            } else {
                                                Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();

                                            }
                                        }
                                    });

                                }

                            });

                            adapter.notifyDataSetChanged();

                        }
                    });

                    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });


                }

                @Override
                public void onLongClick(View view, int position) {

                }
            }));


            list.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
            list.setHasFixedSize(true);

            ListAsesorAdminAsignaTestDrive adapter = new ListAsesorAdminAsignaTestDrive(getApplicationContext(), asesores);
            list.setAdapter(adapter);


            alertDialog.show();


        }
    }));

如果您不知道正确的答案或解决方法,请不要回答。

更新: Android疯了!!。当我进行第一个onLongClick时,警报对话框仍然无法工作,因为我没有办法返回,所以我在警报对话框的外部单击它消失了然后我再点击一次,它就可以工作了!!!这很奇怪为什么会发生????一切都没有改变。

android android-alertdialog
1个回答
0
投票

I。声明对话框背景的自定义drawable.xml。

android:insetLeft="16dp"
android:insetTop="16dp"
android:insetRight="16dp"
android:insetBottom="16dp">
<shape android:shape="rectangle">
    <corners android:radius="2dp" />
    <solid android:color="@color/indigo" />
</shape>

II。在您的styles.xml文件中声明自定义样式。

<!--buttons color-->
<item name="colorAccent">@color/pink</item>
<!--title and message color-->
<item name="android:textColorPrimary">@android:color/white</item>
<!--dialog background-->
<item name="android:windowBackground">@drawable/drawable</item>

III。创建对话框并将样式用作AlertDialog.Builder中的参数。

AlertDialog.Builder builder =新的AlertDialog.Builder(this,R.style.MyDialogTheme);

AlertDialog对话框= builder.create();

dialog.show();

© www.soinside.com 2019 - 2024. All rights reserved.