I have a recyclerview in a fragment. And I am using butterknife library.
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/studentlist" />
then the adapter class will be
public class PeopleAdapter extends RecyclerView.Adapter<PeopleAdapter.MyViewHolder> {
private List<StudentData> dataList;
private Context context;
public PeopleAdapter(List<StudentData> data, Context context) {
this.dataList = data;
this.context = context;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.people_list_item, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
StudentData data=dataList.get(position);
holder.email.setText(data.getEmail());
holder.name.setText(data.getName());
holder.phone.setText(data.getPhoneNo());
}
@Override
public int getItemCount() {
return dataList.size();
}
static class MyViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.name)
TextView name;
@BindView(R.id.email)
TextView email;
@BindView(R.id.phone)
TextView phone;
@BindView(R.id.image)
TextView image;
public MyViewHolder(View view) {
super(view);
ButterKnife.bind(this,view);
}
}
}
I Initialized recyclerview with
LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerview.setLayoutManager(mLayoutManager);
mRecyclerview.setAdapter(new PeopleAdapter(MyConfiguration.getTemData(),getActivity()));
the data generated method
public static List<StudentData> getTemData(){
List<StudentData> dataList=new ArrayList<>();
for (int i=0;i<10;i++){
dataList.add(new StudentData("myemail"+i+"@gmail.com",i*45234523+"","myname"+i));
}
return dataList;
}
list item
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="50dp"
app:srcCompat="@drawable/profilepic"
android:id="@+id/image"
android:layout_marginTop="5dp"
android:layout_height="60dp" />
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/student_listcard_left_margin"
android:layout_marginRight="@dimen/student_listcard_rightmargin"
android:layout_marginTop="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/name"
android:textSize="18sp"
android:textColor="@android:color/black" />
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/phone" />
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/email" />
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_edit"
android:id="@+id/imageView5"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
StudentData class
public class StudentData {
private String name;
private String email;
public StudentData(String email, String phoneNo, String name) {
this.email = email;
this.phoneNo = phoneNo;
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhoneNo() {
return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public StudentData() {
}
private String phoneNo;
}
parent view.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.ex.ex.fragments.student.StudentInformation">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="false">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
app:tabSelectedTextColor="@android:color/white"
app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewpager" />
</android.support.v4.widget.NestedScrollView>
</LinearLayout
So the problem is the recyclerview doesn't show it's items. Please Help me;