Here i am trying to create a custom arraylist, and custom adapter, to show 3 textview, with 3 seperate string array, according to layout that i make.
However, im having a hard time in putting the string array to the specified setter. i am still new in java, really appreciate help. for now, i thought maybe there should be some way to set the string array in the specified setter.
so here is my custom arraylist ( Perrow.java)
public class Perrow {
String Arabic;
String transliteration;
String translation;
public Perrow(String arabic, String transliteration, String translation) {
Arabic = arabic;
this.transliteration = transliteration;
this.translation = translation;
}
public String getArabic() {
return Arabic;
}
public void setArabic(String arabic) {
Arabic = arabic;
}
public String getTransliteration() {
return transliteration;
}
public void setTransliteration(String transliteration) {
this.transliteration = transliteration;
}
public String getTranslation() {
return translation;
}
public void setTranslation(String translation) {
this.translation = translation;
}
}
and my custom adapter ( PerrorAdapter)
public class PerrowAdapter extends ArrayAdapter<Perrow> {
private Context mContext;
private int mResource;
public PerrowAdapter(@NonNull Context context, int resource, @NonNull ArrayList<Perrow> objects) {
super(context, resource, objects);
this.mContext = context;
this.mResource = resource;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
convertView = layoutInflater.inflate(mResource, parent, false);
TextView arabictext = convertView.findViewById(R.id.arabictext);
TextView transliteration = convertView.findViewById(R.id.transliteration);
TextView translation = convertView.findViewById(R.id.translation);
arabictext.setText(getItem(position).getArabic());
transliteration.setText(getItem(position).getTransliteration());
translation.setText(getItem(position).getTranslation());
return convertView;
}
}
for now, it does work if i input manually using arraylist.add for three of them. I need to set the string array in the setter, so that the string array can be displayed properly.