AndroidGuy007 AndroidGuy007 - 1 month ago 7
Java Question

Getting first parameter at location in List<> android java

final List<Data> data = new ArrayList<>();

data.add(new Data("Batman vs Superman", "Following the destruction of Metropolis, Batman embarks on a personal vendetta against Superman ", R.mipmap.ic_apps));
data.add(new Data("X-Men: Apocalypse", "X-Men: Apocalypse is an upcoming American superhero film based on the X-Men characters that appear in Marvel Comics ",R.mipmap.ic_apps));
data.add(new Data("Captain America: Civil War", "A feud between Captain America and Iron Man leaves the Avengers in turmoil. ", R.mipmap.ic_apps));
data.add(new Data("Kung Fu Panda 3", "After reuniting with his long-lost father, Po must train a village of pandas", R.mipmap.ic_apps));
data.add(new Data("Warcraft", "Fleeing their dying home to colonize another, fearsome orc warriors invade the peaceful realm of Azeroth. ", R.mipmap.ic_apps));
data.add(new Data("Alice in Wonderland", "Alice in Wonderland: Through the Looking Glass ", R.mipmap.ic_apps));


that is above code and the Data class is

public class Data implements Comparable<Data>{
public String title;
public String description;
public int imageId;

Data(String title, String description, int imageId) {
this.title = title;
this.description = description;
this.imageId = imageId;
}
}


now i only know position for List data,
how can i get only title for example :- "Batman vs Superman" at position ?

Answer

data.get(pos).title will do the job for you.

And I would suggest you to clear your basics or atleast google your problem before posting it here.

Comments