2017-05-05 27 views
1

私はすでに回答を含むthis投稿を見つけました。しかし、動作しないものがいくつかあります。理由を理解できません。RecyclerView with expandableビュー

@Override 
     public void onBindViewHolder(final ShipViewer.anAdapter.NumberViewHolder holder, final int position) { 

      final int[] mExpandedPosition = {-1}; 
      final boolean isExpanded = position== mExpandedPosition[0]; 
      holder.details.setVisibility(isExpanded?View.VISIBLE:View.GONE); 
      holder.itemView.setActivated(isExpanded); 
      holder.itemView.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        mExpandedPosition[0] = isExpanded ? -1:position; 
        TransitionManager.beginDelayedTransition(recyclerView); 
        notifyDataSetChanged(); 
       } 
      }); 
      holder.bind(position); 
     } 

まず、詳細を解決できません。詳細は私のViewholder内のConstraintLayoutです:

<android.support.constraint.ConstraintLayout 
     android:id="@+id/details" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="0dp" 
     android:visibility="gone" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/bigtextname"> 

     <TextView 
      android:id="@+id/textView10" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 
    </android.support.constraint.ConstraintLayout> 

私の2番目の問題は、recyclerViewを解決できないということです。私はすでにアダプタを挿入しようとしましたが、それも動作しません。

最後に、ここで最終的に多くのことが成果を上げていますか?これは正しいとは思われませんが、私がそれをしなければ、彼らは内なる階級からアクセスするために最終的にする必要があることを私に伝えます。

マイrecyclerView:RecyclerViewの

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ShipRec" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/black"> 

</android.support.v7.widget.RecyclerView> 

初期化:あなたのために有用であろうbignerdranchから

View b = inflater.inflate(R.layout.shipviewerrecview, container, false); 

        if(!shipsCursor.moveToPosition(0)) {return b;} 

        shipropView = (RecyclerView) b.findViewById(R.id.ShipRec); 
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); 
        shipropView.setLayoutManager(layoutManager); 
        shipropView.setHasFixedSize(true); 
shippropAdapter = new ShipViewer.anAdapter(numberofField, Names, Type, Size, MaxSize, Amount); 


        ShipsDbHelper.close(); 
        return b; 
+0

投稿全体アダプターとスニペットあなたのリサイクラーを初期化する場所 – miljon

+0

@miljon done、thanks! – JDoeKnought

答えて

1

おそらくexpandable-recycler-viewライブラリ。

+0

それはうまくいくかもしれませんが、ライブラリがなければそれは良いでしょう、それはありませんか? – JDoeKnought

+0

はい、それは良いライブラリです - 私はこれを使って作業しました。このライブラリの作成者は、非常に人気のある本「Androidプログラミング:The Big Nerd Ranch Guide」の著者です。 – Kostya