I'm new to android and I need help. I couldn't find a link that explains me what I'm going to ask, that's why I'm asking here.
I have a listview with one layout.
My customLayout have some textviews and images, all that I get from 2 jsonArrays inside one json object.
TEXT1 TEXT2 IMAGE1
I want to populate this layout from 2 different Array Lists.
I get this array lists from 2 jsonArrays on my webservice.
My class is a simple one, like this:
public class Example{
private String text;
private String text2;
private String imageLink;
Constructor...
Getter and Setter...
}
I can put the values of ArrayList1 inside the customLayout but not the values of ArrayList2.
Like this:
public class CustomListAdapterStreams extends ArrayAdapter<StreamsData> {
ArrayList<MyClass> ArrayList;
ArrayList<MyClass> ArrayList2;
Context context;
int resource;
public CustomListAdapterStreams(Context context, int resource, ArrayList<MyClass> ArrayList, ArrayList<MyClass> ArrayList2;) {
super(context, resource, ArrayList);
this.ArrayList= ArrayList;
this.context = context;
this.resource = resource;
this.ArrayList2= ArrayList2;
}
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
if (convertView == null){
LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.activity_custom_list_adapter, null);
}
MyClass myclass= ArrayList.get(position);
String getUsername = myclass.getUsername();
String quality = myclass.getQuality();
TextView txtUsername = (TextView) convertView.findViewById(R.id.txtUsername);
txtUsername.setText(getUsername);
and so on
So I need to understand how to put in the same custom layout, in the same views, dinamically, different values. Like when Array List 1 has nothing left, populate the rest of the list with the values of Array List 2.
EDIT:
Answers saying I should put both json arrays in the same arraylist.
By a rookir mistake I thought that I shouldn't mix up two JSONArrays, into the same ArrayList but that is what solved my problems.
Thank you Wizard, I know it was a stupid question. Rookie mistake here.
arrayList2intoarrayList1. Do you want me to show how you do that?