I have a server, from which i get the values that i need(name, date, city, picture_url). To get them are in getValues class. I'm using Json. All the values are saved in an ArrayList called array. I would use them in multiple classes. I would like to call the array in FragmentB. This is the code for the ArrayList
private ArrayList<String> array;
`array = new ArrayList<String>();
array.add(finalresult.getString("picture"));
array.add(finalresult.getString("name"));
array.add(finalresult.getString("date"));
array.add(finalresult.getString("city"));`
Then i thought i needed some kind of function, so it can be called, from other classes. I wanted to name the function, then arguments are numbers, so you can select which element you want, then you just return the object you wanted.
public ArrayList<String> getEvent(int pos)
{
return array.get(pos);
}
But here i get an error:
Required: java.util.ArrayList <java.lang.String>
Found: java.lang.String
In Fragment, i want the specific element of the array, and save it in one string, so i can call it later.
Something like this:
public class FragmentB extends android.support.v4.app.ListFragment{
private GetEvents getEvents = new GetEvents();
private String picture1, name1, city1, date1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
picture1 = getEvents.getArray(0);
name1 = getEvents.getArray(1);
city1 = getEvents.getArray(2);
date1 = getEvents.getArray(3);
}
}
I know that this is wrong. What is the correct way to pass the elements, and then call them in the fragment?
getEventmethod from ArrayList<> to String.. likepublic String getEvent(int pos) { return array.get(pos); }