1

i have a json file with bunch of items diferent categories , and i want to check categorie and if does match with given condition i want to be displayed in listview , this is what i've came up .. but it doent work , listview is empty

ArrayList<HashMap<String, String>> eventsList = new ArrayList<HashMap<String, String>>();

        try {
            JinnerObject = Jobject.getJSONObject("data");
            Jarray = JinnerObject.getJSONArray("events");
            for(int i = 0; i < Jarray.length(); i++){
                JeventObject = Jarray.getJSONObject(i);

                String  _EV_OP1         = JeventObject.getString(EV_OP1);
                String  _EV_OP2         = JeventObject.getString(EV_OP2);
                String  _EV_COEF1       = JeventObject.getString(EV_COEF1);
                String  _EV_COEF2       = JeventObject.getString(EV_COEF2);
                String  _EV_STIME       = JeventObject.getString(EV_STIME);
                String  _EV_HOST        = JeventObject.getString(EV_HOST);
                String  _EV_DESC        = JeventObject.getString(EV_DESC);
                String  _EV_TIP         = JeventObject.getString(EV_TIP);
                String  _EV_CAT         = JeventObject.getString(EV_CAT);

                    if(_EV_CAT == C){
                    HashMap<String, String> Events_map = new HashMap<String, String>();

                    Events_map.put(EV_OP1,      _EV_OP1);
                    Events_map.put(EV_OP2,      _EV_OP2);
                    Events_map.put(EV_COEF1,    _EV_COEF1);
                    Events_map.put(EV_COEF2,    _EV_COEF2);
                    Events_map.put(EV_STIME,    _EV_STIME);
                    Events_map.put(EV_HOST,     _EV_HOST);
                    Events_map.put(EV_DESC,     _EV_DESC);
                    Events_map.put(EV_TIP,      _EV_TIP);

                    eventsList.add(Events_map);
                    }
            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

1 Answer 1

3

change

if(_EV_CAT == C)

to

if(_EV_CAT.equalsIgnoreCase(C))

for comparing Strings always use equalsIgnoreCase or equals because == operator compares two object references to see whether they refer to the same instance

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.