I am working with json. I have been successful in parsing json and can show the result in listview(images and texts). Now I want to write a search function to search in my json output. I have writen a function, it searches name, but all names in json start with UpperCase and that is poses as problem. I had also tested my code without UpperCase case and it was working at that moment. this is my code
public void SearchFunction(String searchWord) {
itemList.clear();
adapter.notifyDataSetChanged();
if (searchWord.equals(" ")) {
for (int i = 0; i < contents.size(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put(KEY_name, contents.get(i).name);
map.put(KEY_id, contents.get(i).id);
itemList.add(map);
}
} else {
for (int i = 0; i < contents.size(); i++) {
if (contents.get(i).name.indexOf(searchWord) >= 0) {
HashMap<String, String> map = new HashMap<String, String>();
map.put(KEY_name, contents.get(i).name);
map.put(KEY_id, contents.get(i).id);
itemList.add(map);
}
}
}
adapter.notifyDataSetChanged();
}
listResult.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
String searchWord = listResult.getText().toString();
list.setVisibility(View.VISIBLE);
SearchFunction(searchWord);
}
});
I want to check if the solution is in UpperCase. I want my code to work pefectly with or without UpperCase. Please help me with the solution.