2017-02-16 16 views
0

とviewpagerにスクロール刚性。つまり、それらは同じxmlレイアウトを使用します。二つの断片で共有Recyclerview表示されないデータは、私は二つの断片<strong></strong> この二つの断片は同じレイアウトを膨張</strong>と<strong>Bを有するViewPagerと活性を有する二つの断片

XML

<android.support.constraint.ConstraintLayout 
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="match_parent" 
android:id="@id/constraintLayout" 
android:background="@color/md_white_1000" 
android:orientation="vertical"> 

    <android.support.v7.widget.RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/propRV" 
     android:scrollbars="vertical" 
     app:layout_constraintTop_toTopOf="@id/constraintLayout" 
     app:layout_constraintLeft_toLeftOf="@id/constraintLayout" 
     app:layout_constraintBottom_toBottomOf="@id/constraintLayout" 
     app:layout_constraintRight_toRightOf="@id/constraintLayout" 
     > 
    </android.support.v7.widget.RecyclerView> 

    //other views 
</android.support.constraint.ConstraintLayout> 

断片

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    return inflater.inflate(R.layout.fragment_items, container, false); 
} 

フラグメントB

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    return inflater.inflate(R.layout.fragment_items, container, false); 
} 

私は二つの断片を含むアクティビティを開くと、断片内の項目はよく現れるが、私は断片Bにスクロールしたときに私は私を上にスクロールしようとするまで、断片BでRecyclerviewの項目が表示されません。 Recyclerview。

フラグメントBのRecyclerviewのアダプタをチェックして、スクロールアップするまでonBindViewHolder()が呼び出されていないことを確認しました。以下その情報付きアダプタ

public class CustomAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { 

private ArrayList<Object> properties; 
private Context context; 

    public CustomAdapter(Context context,ArrayList<Object> properties){ 
    this.properties = properties; 
    this.context = context; 
    } 

    public int getItemViewType(int position) { 
    Object coreDetails = properties.get(position); 
    if(coreDetails instanceof CoreDetails){ 
     return 0; 
    }else{ 
     return 1; 
    } 
    } 
    @Override 
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    if(viewType == 0){ 
    return new RHolder(LayoutInflater.from(context).inflate(R.layout.r_layout,parent,false)); 
    }else{ 
    return new SHolder(LayoutInflater.from(context).inflate(R.layout.s_layout,parent,false)); 
    } 
    } 

@Override 
public long getItemId(int position) { 
    return position; 
    } 

@Override 
public int getItemCount() { 
    return properties.size(); 
    } 

    @Override 
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { 
    final Object object = properties.get(position); 
    //setting data 
    } 

    } 

で、何が私がスクロールアップまで表示しないように断片B Recyclerviewでアイテムを作っていますか?

答えて

0

私はその後、あなたの問題の解決策として、あなたの答えにタグを付けるかもしれない

recyclerview.swapAdapter(myAdapter,false); 
recyclerview.setLayoutManager(myLayoutManager); 
myAdapter.notifyDataSetChanged(); 
+0

を「recyclerviewをリフレッシュする」ことで問題を解決することができました。 :) –

+1

@FelixD。私はそうすることを忘れていた:) –

関連する問題