如何使用firebase UI使2个recyclerView彼此相邻?

时间:2018-03-14 07:09:34

标签: firebase firebase-realtime-database firebaseui

您好我正在使用 Firebase recyclerview UI ,我成功执行了一个RecyclerView,但是当我继续添加第二个时,应用程序会创建错误。

问题是如何以非常简单的形式在同一活动中添加2个回收者?我只想让他们彼此相邻。

我该怎么做? 这是我的代码

public class HarvestingActivity extends AppCompatActivity {
    RecyclerView T;
    RecyclerView S;
DatabaseReference mRefTot;
DatabaseReference mRefSin;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    setContentView(R.layout.activity_harvesting);

    FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
    assert currentUser != null;


    T = (RecyclerView) findViewById(R.id.recyclerviewT);//this is for total 
    T.setLayoutManager(new LinearLayoutManager(this));
    T.setHasFixedSize(true);

    S = (RecyclerView) findViewById(R.id.recyclerviewS);//this is for single 
    S.setLayoutManager(new LinearLayoutManager(this));

     S.setHasFixedSize(true);


    mRefTot = FirebaseDatabase.getInstance().getReference()
            .child("HarvestingActivity")
            .child("TotalActivity");
    FirebaseRecyclerAdapter<TotalUsers, TotalUsersHolder> T_Adapter = new FirebaseRecyclerAdapter<TotalUsers, TotalUsersHolder>(
            TotalUsers.class,
            R.layout.h_item_user_total,
            TotalUsersHolder.class,
            mRefTot

    ) {

        @Override
        protected void populateViewHolder(TotalUsersHolder viewHolder, TotalUsers model, int position) {
            FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
            assert currentUser != null;

            viewHolder.setName(model.getName());
        }
    };
      mRefSin=FirebaseDatabase.getInstance().getReference()
            .child("HarvestingActivity")
            .child("SingleActivity");
             FirebaseRecyclerAdapter<SingleUser,SingleUserHolder> 
            S_Adapter=new 
              FirebaseRecyclerAdapter<SingleUser,SingleUserHolder>(
            SingleUser.class,
            R.layout.h_item_users_single,
            SingleUserHolder.class,
            mRefSin
    ) {
        @Override
        protected void populateViewHolder(SingleUserHolder viewHolder, 
        SingleUser model, int position) {
            FirebaseUser currentUser = 
         FirebaseAuth.getInstance().getCurrentUser();
            assert currentUser != null;
            viewHolder.setName(model.getName());

        }
    };
    T.setAdapter(T_Adapter);

    S.setAdapter(S_Adapter);

}

public static class TotalUsersHolder extends RecyclerView.ViewHolder {
    View view;

    public TotalUsersHolder(View itemView) {
        super(itemView);
        view = itemView;
    }

    public void setName(String name) {
        TextView Harvester_Name = (TextView) view.findViewById(R.id.HarvesterName);
        Harvester_Name.setText(name);
    }
}
private class SingleUserHolder extends RecyclerView.ViewHolder {
    View sview;
    public SingleUserHolder(View itemView) {
        super(itemView);
        sview=itemView;
    }

    public void setName(String name) {
        TextView Answer_Name = (TextView) 
     sview.findViewById(R.id.AnswerName);
        Answer_Name.setText(name);
    }
}

}

0 个答案:

没有答案