Skip to content Skip to sidebar Skip to footer

Android Search List Invisible By Default? Can It Be Done?

Hi guys I have a question: In short, I have a listview, with a searchbar on top of it, I am also able to start my other activities after filtering the results etc; basically everyt

Solution 1:

Go this way: set your listview visibility to gone or invisible from your xml file:

android:visibility="gone"

Now apply textwatcher on searchbar edittext

edittext.addTextChangedListener(newTextWatcher() {
            @OverridepublicvoidonTextChanged(CharSequence s, int start, int before, int count) {

                // TODO Auto-generated method stub//put your search logic here and populate listview.//after populating listview set its visibility to visible
                listView.setVisibility(View.VISIBLE);
                //and set listview visibility to GONE again when user erase all text from search edittextif(s.length() == 0){
                listView.setVisibility(View.GONE);
                } else {
                listView.setVisibility(View.VISIBLE);
                }
            }

            @OverridepublicvoidbeforeTextChanged(CharSequence s, int start, int count, int after) {

                // TODO Auto-generated method stub
            }

            @OverridepublicvoidafterTextChanged(Editable s) {

                // TODO Auto-generated method stub
            }
        });

Post a Comment for "Android Search List Invisible By Default? Can It Be Done?"