0

i spend hole day on looking what is going on. In one class I've got simple listview with multiple choice. At the end each choice is put to String array and share to next class.

SparseBooleanArray checked = listView.getCheckedItemPositions();
        ArrayList<String> selectedItems = new ArrayList<String>();
    for (int i = 0; i < checked.size(); i++) {
        // Item position in adapter
        int position = checked.keyAt(i);
        // Add sport if it is checked i.e.) == TRUE!
        if (checked.valueAt(i))
            selectedItems.add(adapter.getItem(position));
    }

    String[] outputStrArr = new String[selectedItems.size()];

    for (int i = 0; i < selectedItems.size(); i++) {
        outputStrArr[i] = selectedItems.get(i);
    }

   Intent intent = new Intent(getApplicationContext(),
            ReadComments.class);

    // Create a bundle object
    Bundle b = new Bundle();
    b.putStringArray("selectedItems", outputStrArr);

    // Add the bundle to the intent.
    intent.putExtras(b);

    // start the ResultActivity
    startActivity(intent);

In ReadComments class i've made simple method:

public String[] tablica(){
        Bundle b = getIntent().getExtras();
        String[] resultArr = b.getStringArray("selectedItems");
        return resultArr;

    }

which bring back my data. When I put it to another method in the same class:

String resultArr[] = tablica();

        int x = 0;
        for (Map<String, String> mListaMar : mListaMarketow) {
            lat = mListaMar.get(TAG_SZER);
            longi = mListaMar.get(TAG_DLUG);
            name = mListaMar.get(TAG_MARKET);
            x=0;


            for (x = 0; x < resultArr.length; x++) {
                if (resultArr[x] == name) {

                    ustawMape();
                    }}}     

UstawMape() method is responsible for show marker on google map. My problem is a logical problem because everything is working fine but ustawMape() method should show many markers and right now it show only one (construcion of ustawMape() is ok because without for loop it's work ok). The clue is very simple first loop for bring data from JSON and the second one should filter and show only this which user choose in listView. PLZ help my somebody!!

A. Wolff
  • 74,033
  • 9
  • 94
  • 155
bakusek
  • 135
  • 3
  • 17

1 Answers1

1
if (resultArr[x] == name)

Use equals() for string comparisons instead of ==:

if (name.equals(resultArr[x]))

== compares object references which won't be the same unless the strings are interned. equals() compares the string values.

laalto
  • 150,114
  • 66
  • 286
  • 303