Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: How to get ArrayList index value?

Arjun Kumar:

I have an app which contains singleton array list and have the Main activity with listview I am trying to get a value of singleton Arraylist and match with a value of listview and if match then I want to auto select that index. How do I do that

code of singleton ArrayList class

private static NameSingleton ourInstance;
private ArrayList list = null;
public static NameSingleton getInstance() {
if(ourInstance == null)
ourInstance = new NameSingleton();
return ourInstance;

private NameSingleton() {
list = new ArrayList();
// retrieve array from anywhere
public ArrayList getArray() {
return this.list;
//Add element to array
public void addToArray(String value) {
public void removeArray(String value){

code for matching value from singleton with listview value:-

count = NameSingleton.getInstance().getArray().size();
if (count!=0){
for (int i=0;i //Here i want to get value from singleton arraylist class
String name =
//here i want to match that value from listview value if matched then auto select that index in listview
for (int j=0;i UserListingModel model = dataSet.get(j);
if (model.getName().equals(name)){


code for item click:- When i click item 1st time it will selected and on click same item second time it will unselected.

boolean isPressed = true;
if (isPressed){
UserListingModel model = dataSet.get(position);
String name = model.getName();
}else {
UserListingModel model = dataSet.get(position);
Log.e(TAG,"Removed data"+model);

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: How to get ArrayList index value?


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription