I am using an ArrayList
and all the strings are hard coded in the adapter but now I need multi-language support for my app. I think the best way to do this is to move all my hard coded strings to my strings.xml file and then make all the string files I need for the different languages.
I already moved the hard coded strings to my strings.xml but I am not sure now how to call them in the Arraylist
instead of having the hard coded string in there.
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
List<AdapterData> mItems;
public Adapter() {
super();
mItems = new ArrayList<>();
AdapterData data = new AdapterData();
data.setQuestion("How Old Are You?");
data.setAnswer("I Am 21 Years Old");
mItems.add(data);
data = new AdapterData();
data.setQuestion("Where Were You Born?");
data.setAnswer("I Was Born In The USA");
mItems.add(data);
data = new AdapterData();
data.setQuestion("Are You Male or Female?");
data.setAnswer("I Am Male");
mItems.add(data);
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.recycler_view_card_item, viewGroup, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
AdapterData data = mItems.get(i);
viewHolder.mName.setText(data.getQuestion());
viewHolder.mNameTwo.setText(data.getAnswer());
}
@Override
public int getItemCount() {
return mItems.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
public TextView mQuestion;
public TextView mAnswer;
public ViewHolder(View itemView) {
super(itemView);
mQuestion = (TextView)itemView.findViewById(R.id.layoutQuestion);
mAnswer = (TextView)itemView.findViewById(R.id.layoutAnswer);
}
}
}