0

Given a Java object that has certain fields defined such as a User class:

public class User {
public String Largetext;
public String Mediumtext;

public User(String Largetext, String Mediumtext) {
    this.Largetext = Largetext;
    this.Mediumtext = Mediumtext;
}

And ListView is:

String[] excercise1 = {"Wide-Grip Pull-Up", "Wide-Grip Pull-Down", "T-Bar Row", "Seated Cable Row", "Close Grip Row", "One Arm Dumble Row", "Dead Lift"};
    String[] Detail = {"3 Set of 8-12 rep","4 set of 12-15 rep","3 set of 12,10,8 rep","3 set of 10-12 rep","4 set of 10-15 rep","3 set of 10-12 rep","4 set of 10,8,8,6"};
    ArrayList<User> arraylist = new ArrayList<>();
    final int[] imgs1 = {R.drawable.pullup_la, R.drawable.pulldown_la, R.drawable.tbar_la, R.drawable.seated_la, R.drawable.bend_la, R.drawable.onearm_la, R.drawable.dead_la};
    ListAdapter saruadapter = new Backcoutomadapter(this, arraylist, imgs1);
    ListView sarulistview = (ListView) findViewById(R.id.SarulistView);
    sarulistview.setAdapter(saruadapter);

Now how could i merge this two array of string excercise1 and Detail to this arraylist. So i could this arraylist in Backcoutomadapter like this:

public class Backcoutomadapter extends ArrayAdapter<User> {
private int[] imgs1;
private String[] detail;

public Backcoutomadapter(Context context, ArrayList<User> excercise1, int[] imgs) {
    super(context, backcustom_row, excercise1);
    this.imgs1 = imgs;
}

Thanks in advance.

1 Answer 1

1

The items of arrays exercise1 & Detail have one to one relationship, ie. item at position 0 of exercise1 is related to item at position 0 of Detail, right? So, you can just write a for loop till the length of the array, take the strings from the array, & insert into the array list:

for(int i=0;i<exercise1.length();i++){
    User user = new User(exercise1[i], Detail[i]);
    arraylist.add(user);
}

Then pass this arraylist to Backcoutomadapter:

ListAdapter saruadapter = new Backcoutomadapter(this, arraylist, imgs1);

Override & implement the getView method to use the strings in ListView:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Get the data item for this position
    User user = getItem(position);
    ................
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.