I have a fragment in which i have already implemented a recyclerview at the top part off the screen which holds cardview, now i want to create another recyclerview which also adds cardview to the bottom part of the screen in the same fragment.
I'm new to android studio, so knowing where to place what is a problem for me.
This is the fragment code
public HomeFragment(){
//Required empty public constructor
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_home, container, false);
view = inflater.inflate(R.layout.fragment_home, container, false);
mBlogList = (RecyclerView)view.findViewById (R.id.myRecycleView);
mBlogList.setHasFixedSize(true);
mBlogList.setLayoutManager(new LinearLayoutManager(getContext()));
mDatabase = FirebaseDatabase.getInstance().getReference().child("Global");
return view;
}
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Blog, BlogViewHolder>
(Blog.class,R.layout.blog_row, BlogViewHolder.class, mDatabase) {
@Override
protected void populateViewHolder(BlogViewHolder viewHolder, Blog model, int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
viewHolder.setImage(getContext(), model.getImage());
}
};
mBlogList.setAdapter(firebaseRecyclerAdapter);
}
public static class BlogViewHolder extends RecyclerView.ViewHolder{
View mView;
public BlogViewHolder(View itemView){
super(itemView);
mView = itemView;
}
public void setTitle(String title){
TextView post_title = (TextView) mView.findViewById(R.id.post_title);
post_title.setText(title);
}
public void setDesc(String desc){
TextView post_desc = (TextView) mView.findViewById(R.id.post_desc);
post_desc.setText(desc);
}
public void setImage(Context ctx, String image){
ImageView post_image = (ImageView) mView.findViewById(R.id.post_image);
Picasso.with(ctx).load(image).into(post_image);
}
}
}
Now how to add another recycler view?
This is the layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.bahdape.archangels.MainActivity"
xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="285dp"
android:layout_marginTop="2dp"
android:layout_margin="5dp"
android:background="@drawable/rounded_corner">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="285dp"
android:id="@+id/myRecycleView"
android:orientation="horizontal">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</RelativeLayout>