Hi I am trying to get information from multiple string arrays held in a xml file to be output in a card view within a recycler view. I am thinking that I access the arrays through the adapter file for the recycler view, however I am not sure as I am new to this.
My xml file is called events.xml and is located in the res/values folder.
My adapter code is this:
public class EventCalenderAdapter extends RecyclerView.Adapter<EventCalenderAdapter.ViewHolder> {
String[] title;
String[] time_start;
String[] time_finish;
String[] date;
static class ViewHolder extends RecyclerView.ViewHolder {
CardView cardView;
TextView titleView;
TextView auxView1;
TextView auxView2;
TextView auxView3;
public ViewHolder(CardView card) {
super(card);
cardView = card;
titleView = (TextView) card.findViewById(R.id.text1);
auxView1 = (TextView) card.findViewById(R.id.text2);
auxView2 = (TextView) card.findViewById(R.id.text3);
auxView3 = (TextView) card.findViewById(R.id.text4);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
CardView v = (CardView) LayoutInflater.from(parent.getContext()).inflate(R.layout.event_task, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int i) {
viewHolder.titleView.setText(title[i]);
viewHolder.auxView1.setText(time_start[i]);
viewHolder.auxView2.setText(time_finish[i]);
viewHolder.auxView3.setText(date[i]);
}
@Override
public int getItemCount() {
return title.length;
}
}
String[] mydata = getResources.getStringArray(R.array.mystrings);. Then you can pass it to the constructor of the adapter class and use it there. Read developer.android.com/guide/topics/resources/…