1

Hi I am using json response with image and text to display in gridview. It has been displayed successfully. I need to use search on top of gridview using edittext. But search is not working when I give input.

Here is my code.

List<PonyTail> ponyList = new ArrayList<PonyTail>();
private PonyTailAdapter gridAdapter;
private String dataPath;
private EditText search;
    search = (EditText) rootView.findViewById(R.id.hairstyle_name);
    search.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String text= search.getText().toString();
            List<PonyTail> list = searchs(text);
        }
        //this is not working :-(
        private List<PonyTail> searchs(String text) {
            List<PonyTail> list = new ArrayList<PonyTail>();
             for (PonyTail u: ponyList) {  // listUsers= contains all data parsed in asynckTask
                 if(u.getName().startsWith(text))//get name.
                 {
                     list.add(u);
                 }
               }
            return list;
        }

  in doInBackground:
this what I parse and dsiplay in gridview.
    private void parseResult(String result) {
        try {
            JSONObject jsono = new JSONObject(result);
            JSONArray jarray = jsono.getJSONArray(Constants.HAIRSTYLE);
            for (int i = 0; i < jarray.length(); i++) {
                JSONObject object = jarray.getJSONObject(i);
                PonyTail ponyTail = new PonyTail();
                ponyTail.setName(object.getString(Constants.NAME));
                ponyTail.setImage(object.getString(Constants.IMAGE));
                ponyTail.setDescription(object
                        .getString(Constants.DESCRIPTION));
                ponyList.add(ponyTail);

            }

        } catch (Exception e) {
            e.printStackTrace();
        }
  • I can't see you calling `notifyDatasetChanged` on your adapter anywhere. You also seem to imply you are trying to update the UI from a background thread. This is a very big problem – Marcus Hooper Oct 11 '15 at 10:00

0 Answers0