-5

こんにちは、RecyclerViewと同じを画像as shown in imageに示すように追加しますが、すでに最初にrecyclerview click here to view implemntedを行っています。私は既存のコードでもう1つを追加する方法を知りません。私を助けてください。マイRecyclerViewコード2つのリサイクルビューを同じフレームに追加するには

Communication.class

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 

    View view = inflater.inflate(R.layout.fragment_communication_summary, container, false); 

    mRecyclerView = (RecyclerView) view.findViewById(R.id.comm_expected_recycler_view); 

    mRecyclerView.setHasFixedSize(true); 
    mRecyclerView.setHasFixedSize(true); 
    mRecyclerViewLayoutManager = new LinearLayoutManager(getContext()); 
    mRecyclerView.setLayoutManager(mRecyclerViewLayoutManager); 

private class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.ViewHolder> { 

    private List<CommunicationVO> mCommunicationVOsList; 

    public MyRecyclerViewAdapter(List<CommunicationVO> communicationVOsList) { 

     mCommunicationVOsList = communicationVOsList; 
    } 

@Override 
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 

     View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.communication_summary_list_item, parent, false); 

     ViewHolder viewHolder = new ViewHolder(view); 

     return viewHolder; 
    } 
@Override 
    public void onBindViewHolder(ViewHolder holder, int position) { 

     if (holder != null) { 

      CommunicationVO communicationVO = mCommunicationVOsList.get(position); 

      holder.expInvoiceNumber.setText(communicationVO.getExpInvoiceNumber()); 
      holder.expAmount.setText(CashPunditUtils.formatAmount(communicationVO.getExpAmount())); 
      holder.expDueDate.setText(CashPunditUtils.formatDate(CashPunditUtils.extractDateAndTime(communicationVO.getExpDueDate()), "dd-MMM-yy")); 
      holder.expPromisedDate.setText(CashPunditUtils.formatDate(CashPunditUtils.extractDateAndTime(communicationVO.getExpPromisedDate()), "dd-MMM-yy")); 

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

    public class ViewHolder extends RecyclerView.ViewHolder { 

     public TextView expInvoiceNumber, expAmount, expDueDate, expPromisedDate; 

     public ViewHolder(View itemView) { 

      super(itemView); 

      expInvoiceNumber = (TextView) itemView.findViewById(R.id.textview_invnum); 
      expAmount = (TextView) itemView.findViewById(R.id.textview_amount); 
      expDueDate = (TextView) itemView.findViewById(R.id.textview_duedate); 
      expPromisedDate = (TextView) itemView.findViewById(R.id.textview_promisedate); 
     } 
    } 
+0

https://stackoverflow.com/questions/26245139/how-to-create-recyclerview-with-multiple-view-type –

答えて

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_one" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_two" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" /> 
</LinearLayout> 

そして、あなたのJavaコードでは、同じアダプタの2つの異なるインスタンスを作成し、同じ見解を持っているviews.Since両方のリサイクル業者にそのアダプタを設定し、あなたは両方のリサイクルビューのために同じアダプタを使用することができます。これはあなたを助けてくれるでしょう。

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 

    View view = inflater.inflate(R.layout.fragment_communication_summary, container, false); 


    //RecyclerView One 
    mRecyclerView1 = (RecyclerView) view.findViewById(R.id.recycler_one); 
    mRecyclerView1.setHasFixedSize(true); 
    adapter1=newMyRecyclerViewAdapter(communicationVOsList); 
    mRecyclerViewLayoutManager1 = new LinearLayoutManager(getContext()); 
    mRecyclerView1.setLayoutManager(mRecyclerViewLayoutManager1); 
    mRecyclerView1.setAdapter(adapter1); 

    //RecyclerView two 
    mRecyclerView2 = (RecyclerView) view.findViewById(R.id.recycler_two); 
    adapter2=newMyRecyclerViewAdapter(communicationVOsList); 
    mRecyclerView2.setHasFixedSize(true); 
    mRecyclerViewLayoutManager2 = new LinearLayoutManager(getContext()); 
    mRecyclerView2.setLayoutManager(mRecyclerViewLayoutManager2); 
    mRecyclerView2.setAdapter(adapter2); 

    private class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.ViewHolder> { 

     private List<CommunicationVO> mCommunicationVOsList; 
     public MyRecyclerViewAdapter(List<CommunicationVO> communicationVOsList) { 
      mCommunicationVOsList = communicationVOsList; 
     } 

     @Override 
     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 

      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.communication_summary_list_item, parent, false); 
      ViewHolder viewHolder = new ViewHolder(view); 
      return viewHolder; 
     } 
     @Override 
     public void onBindViewHolder(ViewHolder holder, int position) { 

      if (holder != null) { 

       CommunicationVO communicationVO = mCommunicationVOsList.get(position); 
       holder.expInvoiceNumber.setText(communicationVO.getExpInvoiceNumber()); 
       holder.expAmount.setText(CashPunditUtils.formatAmount(communicationVO.getExpAmount())); 
       holder.expDueDate.setText(CashPunditUtils.formatDate(CashPunditUtils.extractDateAndTime(communicationVO.getExpDueDate()), "dd-MMM-yy")); 
       holder.expPromisedDate.setText(CashPunditUtils.formatDate(CashPunditUtils.extractDateAndTime(communicationVO.getExpPromisedDate()), "dd-MMM-yy")); 

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

     public class ViewHolder extends RecyclerView.ViewHolder { 

      public TextView expInvoiceNumber, expAmount, expDueDate, expPromisedDate; 
      public ViewHolder(View itemView) { 
       super(itemView); 
       expInvoiceNumber = (TextView) itemView.findViewById(R.id.textview_invnum); 
       expAmount = (TextView) itemView.findViewById(R.id.textview_amount); 
       expDueDate = (TextView) itemView.findViewById(R.id.textview_duedate); 
       expPromisedDate = (TextView) itemView.findViewById(R.id.textview_promisedate); 
      } 
     } 

EDIT

いけないrecyclerview.Addにこれらのコード行をadapdterオブジェクトを作成し、一度試してみることを忘れ。

mRecyclerViewAdapter = new MyRecyclerViewAdapter(mCommunicationVOsList); 
      mRecyclerView.setAdapter(mRecyclerViewAdapter); 
+0

ありません、私はすでにXML 1以上RecyclerViewに追加したが、私はどのように記入したいですもう1つRecyclerView –

+0

彼はあなたに無料でコードを作っています。本当にここでは奨励されていません。 –

+0

私はそうは思わない...しかし何でも...しかし、それは同様の状況に遭遇する他の人を助ける。 – Anonymous

関連する問題