I know that this question has been asked many times, but the answers doesn't work for me. I am trying to use Horizontal placement. Here is my code:
public class CalendarDaysAdapter extends RecyclerView.Adapter<CalendarDaysAdapter.MyViewHolder> {
private ArrayList<String> list;
public CalendarDaysAdapter(ArrayList<String> list)
{
this.list = list;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_calendar_days_item, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
String day = list.get(position);
holder.daystxt.setText(day);
}
@Override
public int getItemCount() {
return list.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView daystxt;
public MyViewHolder(View view) {
super(view);
daystxt = (TextView) view.findViewById(R.id.daystxt);
}
}
}
fragment_calendar_days_item xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center">
<TextView
android:id="@+id/daystxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MON"
android:textSize="20sp"/>
</RelativeLayout>
</LinearLayout>
I tried every combination of wrap_content - match_parent, also on the RecyclerView xml in parent Activity, but only the first item is showing. I have used breakpoints to see if the data of the list are there, and they are.
So what I am missing ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…