android .widget.LinearLayout нельзя преобразовать в androidx.recyclerview.widget.RecyclerView - PullRequest
0 голосов
/ 05 мая 2020

Привет, в приведенном ниже коде я столкнулся с проблемой android .widget.LinearLayout не может быть преобразован в androidx.recyclerview.widget.RecyclerView. Я реализую перетаскивание элементов списка recyclerview. Когда я перетаскиваю элемент, он выдает ошибку и падение или перемещение вызывает ошибку.

Может ли кто-нибудь помочь мне решить эту проблему.

public class DragListener implements View.OnDragListener {

        boolean isDropped = false;
        Listener mListener;

        public DragListener(Listener listener) {
            this.mListener = listener;
        }

        @Override
        public boolean onDrag(View v, DragEvent event) {
            int action = event.getAction();
            switch (action) {
                case DragEvent.ACTION_DRAG_STARTED:
                    break;

                case DragEvent.ACTION_DRAG_ENTERED:
                    //v.setBackgroundColor(Color.LTGRAY);
                    break;

                case DragEvent.ACTION_DRAG_EXITED:
                    //v.setBackgroundColor(Color.YELLOW);
                    break;

                case DragEvent.ACTION_DROP:

                    isDropped = true;
                    int positionSource = -1;
                    int positionTarget = -1;

                    View viewSource = (View) event.getLocalState();

                    if (v.getId() == R.id.cardView || v.getId() == R.id.textEmptyList) {
                        //RecyclerView target = (RecyclerView) v.getParent();
                        RecyclerView target;
                        if (v.getId() == R.id.textEmptyList) {
                            target = (v.findViewById(R.id.recyclerNegotiation));
                                    v.getRootView().findViewById(R.id.recyclerNegotiation);
                        } else {
                            target = (v.findViewById(R.id.recyclerNegotiation));
                            v.getParent();
                            positionTarget = (int) v.getTag();
                        }

                        RecyclerView source = (RecyclerView) viewSource.getParent();

                        NegotiationAdapter adapterSource = (NegotiationAdapter) source.getAdapter();
                        positionSource = (int) viewSource.getTag();

                        ModelTest customList = (ModelTest) adapterSource.getCustomList().get(positionSource);
                        ArrayList<ModelTest> customListSource = adapterSource.getCustomList();

                        customListSource.remove(positionSource);
                        adapterSource.updateCustomList(customListSource);
                        adapterSource.notifyDataSetChanged();

                        NegotiationAdapter adapterTarget = (NegotiationAdapter) target.getAdapter();
                        ArrayList<ModelTest> customListTarget = adapterTarget.getCustomList();
                        if (positionTarget >= 0) {
                            customListTarget.add(positionTarget, customList);
                        } else {
                            customListTarget.add(customList);
                        }
                        adapterTarget.updateCustomList(customListTarget);
                        adapterTarget.notifyDataSetChanged();
                        v.setVisibility(View.VISIBLE);

                        if (source.getId() == R.id.recyclerNegotiation
                                && adapterSource.getItemCount() < 1) {
                            mListener.setEmptyList(true);
                        }

                        if (v.getId() == R.id.textEmptyList) {
                            mListener.setEmptyList(false);
                        }
                    }

                    break;

                case DragEvent.ACTION_DRAG_ENDED:
                    //v.setBackgroundColor(0);
                    break;

                default:
                    break;
            }

            if (!isDropped) {
                View vw = (View) event.getLocalState();
                vw.setVisibility(View.VISIBLE);
            }

            return true;
        }

    }

fragment_ne go. xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/back_blue"
    android:id="@+id/contact_card"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_anchorGravity="center"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/card_details">



            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/cards"
                android:background="@color/back_blue">



<!--                    <LinearLayout-->
<!--                        android:id="@+id/bottom_wrapper"-->
<!--                        android:layout_width="wrap_content"-->
<!--                        android:layout_height="match_parent"-->
<!--                        android:weightSum="4"-->
<!--                        android:orientation="vertical">-->


<!--                        <ImageView-->
<!--                            android:id="@+id/share"-->
<!--                            android:src="@drawable/share"-->
<!--                            android:layout_width="70dp"-->
<!--                            android:paddingLeft="15dp"-->
<!--                            android:layout_weight="2"-->
<!--                            android:background="@color/back_blue"-->
<!--                            android:paddingRight="15dp"-->
<!--                            android:layout_height="match_parent" />-->
<!--                        <View-->
<!--                            android:layout_width="fill_parent"-->
<!--                            android:layout_height="2dp"-->
<!--                            android:background="@color/slivergray"-->
<!--                            android:layout_below="@id/share"/>-->
<!--                        <ImageView-->
<!--                            android:id="@+id/edit"-->
<!--                            android:src="@drawable/ic_launcher"-->
<!--                            android:layout_width="70dp"-->
<!--                            android:background="@color/back_blue"-->
<!--                            android:layout_weight="2"-->
<!--                            android:paddingLeft="15dp"-->
<!--                            android:paddingRight="15dp"-->
<!--                            android:layout_height="match_parent" />-->

<!--                    </LinearLayout>-->

                    <androidx.cardview.widget.CardView
                        android:id="@+id/cardView"
                        android:layout_width="350dp"
                        android:layout_height="wrap_content"
                        app:cardBackgroundColor="@color/slivergray"
                        app:cardCornerRadius="5dp"
                        app:cardElevation="4dp"
                        app:cardUseCompatPadding="true">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="vertical"
                            android:background="@color/White">

                            <TextView
                                android:id="@+id/potential_name"
                                style="@style/Base.TextAppearance.AppCompat.Subhead"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/names"
                                android:paddingLeft="16dp"
                                android:layout_marginTop="3sp"
                                android:text="Potential Name"
                                android:textStyle="bold"
                                android:paddingRight="16dp"
                                android:textColor="@color/gray"
                                android:textSize="18sp"/>

                            <TextView
                                android:id="@+id/account_name"
                                style="@style/Base.TextAppearance.AppCompat.Subhead"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/potential_name"
                                android:paddingLeft="16dp"
                                android:text="Account Name"
                                android:textStyle="bold"
                                android:paddingRight="16dp"
                                android:textColor="@color/gray"
                                android:textSize="15sp"/>

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal"
                                android:id="@+id/assigned"
                                android:layout_below="@+id/account_name"
                                android:weightSum="3">

                                <TextView
                                    android:id="@+id/text_ass"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    android:layout_weight="1"
                                    android:layout_below="@+id/bill_city"
                                    android:paddingLeft="16dp"
                                    android:paddingRight="16dp"
                                    android:text="Assigned"
                                    android:textColor="@color/gray"
                                    android:textSize="15sp" />
                                <TextView
                                    android:id="@+id/assigned_to"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/text_spec"
                                    android:layout_weight="2"
                                    android:textColor="@color/gray"
                                    android:textSize="15sp"/>

                            </LinearLayout>


                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal"
                                android:id="@+id/streets"
                                android:layout_below="@+id/assigned"
                                android:weightSum="3">

                                <TextView
                                    android:id="@+id/text_spec"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    android:layout_weight="1"
                                    android:layout_below="@+id/bill_city"
                                    android:paddingLeft="16dp"
                                    android:paddingRight="16dp"
                                    android:text="Contact"
                                    android:textColor="@color/gray"
                                    android:textSize="15sp" />
                                <TextView
                                    android:id="@+id/contact_name"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/text_spec"
                                    android:layout_weight="2"
                                    android:textColor="@color/gray"
                                    android:textSize="15sp"/>

                            </LinearLayout>

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal"
                                android:id="@+id/citys"
                                android:weightSum="3"
                                android:layout_below="@+id/streets">

                                <TextView
                                    android:id="@+id/text_city"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/citys"
                                    android:paddingLeft="16dp"
                                    android:text="Location"
                                    android:paddingRight="16dp"
                                    android:layout_weight="1"
                                    android:textColor="@color/gray"
                                    android:textSize="15sp"
                                    />
                                <TextView
                                    android:id="@+id/location"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/text_city"
                                    android:layout_weight="2"
                                    android:textColor="@color/gray"
                                    android:textSize="15sp"/>

                            </LinearLayout>


                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal"
                                android:id="@+id/items"
                                android:weightSum="3"
                                android:layout_below="@+id/citys">

                                <TextView
                                    android:id="@+id/text_district"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/bill_district"
                                    android:paddingLeft="16dp"
                                    android:paddingRight="16dp"
                                    android:text="Product"
                                    android:layout_weight="1"
                                    android:textColor="@color/gray"
                                    android:textSize="15sp" />
                                <TextView
                                    android:id="@+id/item_name"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/text_district"
                                    android:layout_weight="2"
                                    android:text="product"
                                    android:paddingRight="16dp"
                                    android:textColor="@color/gray"
                                    android:textSize="15sp"/>
                            </LinearLayout>


                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal"
                                android:id="@+id/amounts"
                                android:weightSum="3"
                                android:layout_below="@+id/items"
                                android:layout_marginBottom="4dp">

                                <TextView
                                    android:id="@+id/text_total"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/bill_district"
                                    android:layout_weight="1"
                                    android:text="Value(Qty)"
                                    android:paddingLeft="16dp"
                                    android:textColor="@color/gray"
                                    android:textSize="15sp"
                                    />
                                <LinearLayout
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:weightSum="3"
                                    android:paddingLeft="2dp">
                                    <TextView
                                        android:id="@+id/amount"
                                        style="@style/Base.TextAppearance.AppCompat.Subhead"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_below="@+id/text_total"
                                        android:text="@string/Rs"
                                        android:layout_weight="1"
                                        android:textColor="@color/gray"
                                        android:textSize="15sp"/>

                                    <TextView
                                        android:id="@+id/text_qty"
                                        style="@style/Base.TextAppearance.AppCompat.Subhead"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_below="@+id/salutations"
                                        android:layout_weight="1"
                                        android:text="qty"
                                        android:textColor="@color/gray"
                                        android:textSize="15sp"
                                        />

                                    <TextView
                                        android:id="@+id/win_prob"
                                        android:layout_width="50dp"
                                        android:layout_height="wrap_content"
                                        android:text="30%"
                                        android:textColor="@color/White"
                                        android:layout_weight="1"
                                        android:layout_marginLeft="52dp"
                                        android:layout_gravity="center"
                                        android:gravity="center"
                                        android:layout_alignParentRight="true"
                                        android:layout_alignParentTop="true"
                                        />

                                </LinearLayout>


                            </LinearLayout>



                            <View
                                android:layout_width="fill_parent"
                                android:layout_height="2dp"
                                android:background="@color/slivergray"
                                android:layout_below="@id/amounts"/>

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal"
                                android:weightSum="2"
                                android:layout_below="@id/amounts">


                                <TextView
                                    android:id="@+id/potential_no"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/account_name"
                                    android:paddingLeft="16dp"
                                    android:text="Potenial No."
                                    android:layout_weight="1"
                                    android:textStyle="bold"
                                    android:textColor="@color/gray"
                                    android:textSize="15sp"/>
                                <Button
                                    android:id="@+id/pdf"
                                    style="@style/Base.Widget.AppCompat.Button.Borderless"
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    android:text="View QUOTE"
                                    android:layout_weight="1"
                                    android:inputType="text"
                                    android:textColor="@color/password"
                                    android:textSize="15sp"
                                    android:textStyle="bold" />
                            </LinearLayout>
                        </RelativeLayout>
                    </androidx.cardview.widget.CardView>




            </LinearLayout>



        </LinearLayout>


    </FrameLayout>



</RelativeLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...