Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4005998
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:27:43+00:00 2026-05-20T08:27:43+00:00

Is it possible with Android to have a search bar for a ListView so

  • 0

Is it possible with Android to have a search bar for a ListView so that when the search bar is touched a keyboard pops up, and when text is typed into the search bar, the items that match in the ListView are shown?

What I really need is the search bar that brings up a keyboard.

Update:

I’ve added the EditText field that brings up a keyboard and I can type into the EditText field. What I want is to have the first few characters of the items in the list shown in the ListView match the characters typed into the EditText window.

I’ve tried following the approach listed here ListView Filter but I am a little confused as to how much filtering is already done in ListView?

1) Do I need to create a separate array that stores the values that match the text typed into EditText? From this post Call adapter.notifyDataSetChanged, it appears that ListView already has a shadow array to do this, and it gets updated when adapter.notifyDataSetChanged(); is called.

2) Do I need to call adapter.notifyDataSetChanged(); to have ListView updated after I type some text in the EditText window?

3) Do I need to extend ListActivity as this post indicates? If so how do I extend my activity class if the activity class is already being extended from the main activity?

4) What I currently have is the following:

ArrayAdapter<String> adapter = null;
private EditText filterText = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.symptom);
    ListView symptomList = (ListView) findViewById(R.id.ListView_Symptom);
    symptomList.setTextFilterEnabled(true);
    symptomList.setFastScrollEnabled(true);
    filterText = (EditText) findViewById(R.id.search_box);
    filterText.addTextChangedListener(filterTextWatcher);

    adapter = new ArrayAdapter<String>(this, R.layout.menu_item, symptomsArray);
    symptomList.setAdapter(adapter);

    private TextWatcher filterTextWatcher = 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) {
            adapter.getFilter().filter(s);
            adapter.notifyDataSetChanged();
        }

    };

Unfortunately at the moment when I type in the EditText box, I get a NullPointer Exception in

 Thread [<7> Filter] (Suspended (exception NullPointerException))   
ArrayAdapter$ArrayFilter.performFiltering(CharSequence) line: 437   
Filter$RequestHandler.handleMessage(Message) line: 234  
Filter$RequestHandler(Handler).dispatchMessage(Message) line: 99    
Looper.loop() line: 123 
HandlerThread.run() line: 60    

Any idea what I am missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:27:43+00:00Added an answer on May 20, 2026 at 8:27 am

    You have done very small mistake :- create array adapter before setting text changed Listener to the edit text

    see the corrected code

    public class SearchListView extends Activity
    {
    
    
    /** Called when the activity is first created. */
    
    private ListView lv1;
    private String lv_arr[] =
    { "Android", "iPhone", "BlackBerry", "me", "J2ME", "Listview", "ArrayAdapter", "ListItem", "Us", "UK", "India" };
    ListView lst;
    EditText edt;
    ArrayAdapter<String> arrad;
    
    
    
    @Override
    public void onCreate( Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
    
        lv1=(ListView)findViewById(R.id.ListView01);
        edt = (EditText) findViewById(R.id.EditText01);
    
         arrad =  new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr);
         lv1.setAdapter(arrad);
    
        // By using setTextFilterEnabled method in listview we can filter the listview items.
    
         lv1.setTextFilterEnabled(true);
         edt.addTextChangedListener(new TextWatcher()
        {
    
    
            @Override
            public void onTextChanged( CharSequence arg0, int arg1, int arg2, int arg3)
            {
                // TODO Auto-generated method stub
    
            }
    
    
    
            @Override
            public void beforeTextChanged( CharSequence arg0, int arg1, int arg2, int arg3)
            {
                // TODO Auto-generated method stub
    
            }
    
    
    
            @Override
            public void afterTextChanged( Editable arg0)
            {
                // TODO Auto-generated method stub
                SearchListView.this.arrad.getFilter().filter(arg0);
    
            }
        });
    
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have Android running on x86 computers?
Possible Duplicate: Intent to launch the clock application on android I have a widget
Some Android devices don't have Android Market, like Korea, etc. Is it possible to
Do the Android users have the chance to reset the NetworkProvider, so that the
I have a layout that uses an EditText to let users search a database
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
I have an activity handling search ( ACTIVITY_1 ), which works perfectly when I
I have an Activity with an AutoComplete box on it. Whenever the text changes,
I need to have a Edittext beside a Search button . The EditText should
Does Android have an equivalent to Cocoa's viewDidLoad and viewDidAppear functions? If not, then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.