Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Custom Search in ListView

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 560
    Comment on it

    In OnCreate() Method add addTextChangedListener(new TextWatcher() to an EditText View

    example:

      searchEditText.addTextChangedListener(new TextWatcher() {
                @Override
                public void onTextChanged(CharSequence s, int start, int before,
                        int count) {      }
    
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub
            }
    
            @Override
            public void afterTextChanged(Editable s) {
                System.out.println("in Add text change Listner afterText change "+s);
                searchLocation(s.toString());
            }
        });
    
    

    Use Custom adapter to Set the ListView. By using on listview.setAdapter(adapter);

    Create a Function for search list:

    public void searchLocation(String search) { SEARCH_DATA.clear();
    int c=0; for(int i=0;i

                SEARCH_DATA.add(holder);
                System.out.println("Name searched ::"+SEARCH_DATA.get(c).getName());
                c++;
                //favArray[i]=DATA.get(i).name+" "+DATA.get(i).number;
            }
        }
    
        adapter.notifyDataSetChanged();
        //adapter.notifyDataSetInvalidated();
        //setupLocationListView.invalidate();
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: