2017-02-07 11 views
1

ドラッグアンドドロップに問題があります。Androidのドラッグ&ドロップでスタックカードのフラグメント

ここで私のシナリオは、カードのセットを含む1つのフラグメントと、カードの1つにドラッグ・アンド・ドロップの要素、つまり優先度を考慮したテキストビューが含まれています。

Here the tutotrial for the drag and drop

This the youtube video for the same

私は別のアクティビティをintrodusesときの例では、正常に動作しています。しかし、それは私がフラグメントスワイプカードでやっているときに問題を引き起こします。積み重ねられたカードが含まれている

エラーログ

02-07 12:09:49.271 17876-17876/com.panenviron E/AndroidRuntime: FATAL EXCEPTION: main 
                      Process: com.panenviron, PID: 17876 
                      java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.ViewGroup.getChildCount()' on a null object reference 
                       at com.panenviron.fragments.TaskCardListShow.onCreateView(TaskCardListShow.java:61) 

TaskCardListShow.javaフラグメント、私はドラッグを実装し、ここでのコンセプトをドロップしようとしていたときに細かい作業これはアプリのクラッシュ

を起こしています

はコードです

Card_3.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    card_view:cardCornerRadius="@dimen/card_corner_radius" 
    card_view:cardElevation="@dimen/elevation_large" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <com.jmedeisis.draglinearlayout.DragLinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/drag_drop_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <TextView 
       android:id="@+id/drag_drop_textview1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:background="#fff" 
       android:elevation="3dp" 
       android:gravity="center" 
       android:padding="30dp" 
       android:text="P - 3" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/drag_drop_textview" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:background="#fff" 
       android:elevation="3dp" 
       android:gravity="center" 
       android:padding="30dp" 
       android:text="P - 2" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/drag_drop_textview2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:background="#fff" 
       android:elevation="3dp" 
       android:gravity="center" 
       android:padding="30dp" 
       android:text="P - 4" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/drag_drop_textview3" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:background="#fff" 
       android:elevation="3dp" 
       android:gravity="center" 
       android:padding="30dp" 
       android:text="P - 5" 
       android:textStyle="bold" /> 

     </com.jmedeisis.draglinearlayout.DragLinearLayout> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

のGradle

compile 'com.jmedeisis:draglinearlayout:1.1.0' 

答えて

2

私の間違いは間違った方法でレイアウトにアクセスするためのイムtryiongです。つまり、もしドラッグドロップLISを参照してくださいが、ここで私は別の問題を抱えているにもある私のドラッグを来て、そこにフィールドにアクセスしようとしているレイアウトイムをドロップするので、私はちょうど

if(position==2){ // drag and layou card will come at this condition. 
        DragLinearLayout dragDropAndroidLinearLayout = 
          (DragLinearLayout) findViewById(R.id.drag_drop_layout); 
        for (int i = 0; i < 3; i++) { 
         View child = dragDropAndroidLinearLayout.getChildAt(i); 
         dragDropAndroidLinearLayout.setViewDraggable(child, child); 
        } 
       } 

を変更し、今私ができる午前の前に、

ドラッグ&ドロップでテキストビューをドロップすることはできません。それは以前の位置に再び行きます。私は誰ですか?あなたが解決するのを助けてくれますか?

関連する問題