Only returns an index of -1 when there is a match

I am trying to get the index of an item in an array that is selectable in a list view.

The issue is that when I click on the item, it only returns the index of -1, which means that it doesn't match when in fact there should be a match.

What am I doing wrong?

package com.goldleaf.branden.goldleafcomics;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.kosalgeek.genasync12.*;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class GlimpseListFragment extends ListFragment {
    List<String> glimpse = new ArrayList<String>();
    List<String> titles = new ArrayList<String>();
    List<UniverseListing> universalListings = new ArrayList<UniverseListing>();

    public GlimpseListFragment() {

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        ViewGroup rootView = (ViewGroup)inflater.inflate(R.layout.fragment_glimpse_list, container, false);

        return rootView;

    public void onCreate(@Nullable Bundle savedInstanceState) {

        String url = "";
        PostResponseAsyncTask task = new PostResponseAsyncTask(getActivity(), new AsyncResponse() {
            public void processFinish(String s) {
                universalListings = new JsonConverter<UniverseListing>().toArrayList(s, UniverseListing.class);
                Toast.makeText(getActivity(), "Application Data Refreshed", Toast.LENGTH_LONG).show();

                ArrayList<String> glimpse = new ArrayList<String>();
                for(UniverseListing value: universalListings){

                ArrayList<String> titles = new ArrayList<String>();
                for(UniverseListing value: universalListings){

                ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, titles);


    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        String value = (String)getListAdapter().getItem(position);

        int index = this.titles.indexOf(value);
        String value2 = Integer.toString(index);

        Toast.makeText(getActivity(), value2, Toast.LENGTH_LONG).show();


  • you define glimpse two times, could you try to make those changes,

    List<String> glimpse; 

    and inside onCreate initialize it

    glimpse = new ArrayList<>(); 

    and do the same for titles and universalListings.