0

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.

Mr Learning
  • 73
  • 1
  • 9
  • Can you give an example of the code that calls this that fails? – markspace Feb 26 '21 at 16:13
  • i am sorry but it doesnt fail, my problems are how do i call string array in setter and getter ? im defining the string[] in my main java, however, i still cannot call string array that i already defined. – Mr Learning Feb 26 '21 at 16:21
  • what about to set String[] in custom arraylist ? to make it work with custom adapter, it need int right ? so how do i solve it ? – Mr Learning Feb 26 '21 at 16:58

0 Answers0