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

  • Home
  • SEARCH
  • 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 6752017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:59:44+00:00 2026-05-26T12:59:44+00:00

I was following this example: http://developer.android.com/resources/tutorials/views/hello-autocomplete.html And I want to know how I can

  • 0

I was following this example:

http://developer.android.com/resources/tutorials/views/hello-autocomplete.html

And I want to know how I can implement this with a ListView instead of the dropdown window that is supplied with this TextView.

For instance, as the user types into the textView, there is a ListView directly below the textView that will be constantly changing as the user types in the textView field.

EDIT: Here is the solution that I coded with thanks to Josephus:

package com.jaylefler.contacts;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class ContactProjectActivity extends Activity {
    /** Called when the activity is first created. */

    // List of all contacts
    private ArrayList<String> searchNames = new ArrayList<String>();
    // Filtered list of contacts after user begins typing in search field
    private ArrayList<String> partialNames = new ArrayList<String>();

    // List of names matching criteria are listed here
    private ListView myList;

    // Field where user enters his search criteria
    private EditText nameCapture;

    // Adapter for myList
    private ArrayAdapter<String> adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Set list adapter
        myList = (ListView) findViewById(R.id.names);
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, partialNames);
        myList.setAdapter(adapter);

        searchNames.add("Tom Arnold");
        searchNames.add("Zeb Arnold");
        searchNames.add("Dan Bateman");
        searchNames.add("Tommy Canders");
        searchNames.add("Elijah Arnman");
        searchNames.add("Tomas Muster");
        searchNames.add("Stefan Edberg");
        searchNames.add("Ivan Lendl");


        nameCapture = (EditText) findViewById(R.id.name);
        nameCapture.setText("Tom");

        AlterAdapter();

        nameCapture.addTextChangedListener(new TextWatcher() {

            // As the user types in the search field, the list is
            @Override
            public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
                AlterAdapter();
            }

            // Not used for this program
            @Override
            public void afterTextChanged(Editable arg0) {

            }

            // Not uses for this program
            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
                // TODO Auto-generated method stub

            }
        });
    }

    // Filters list of contacts based on user search criteria. If no information is filled in, contact list will be blank.
    private void AlterAdapter() {
        if (nameCapture.getText().toString().isEmpty()) {
            partialNames.clear();
            adapter.notifyDataSetChanged();
        }
        else {
            partialNames.clear();
            for (int i = 0; i < searchNames.size(); i++) {
                if (searchNames.get(i).toString().toUpperCase().contains(nameCapture.getText().toString().toUpperCase())) {
                    partialNames.add(searchNames.get(i).toString());
                }
                adapter.notifyDataSetChanged();
            }
        }
    }
}
  • 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-26T12:59:44+00:00Added an answer on May 26, 2026 at 12:59 pm
    <yourEditText>.addTextChangedListener(new TextWatcher() {
    
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                <requery/filter your adapter then set it to your listview>
                }
    
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    // TODO Auto-generated method stub
    
                }
    
                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub
    
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following the example here: http://developer.android.com/resources/tutorials/views/hello-tabwidget.html Everything works fine. The first time I click
In the ImageAdapter class of this tutorial, http://developer.android.com/resources/tutorials/views/hello-gridview.html I would like to create and
I am following the Android Gallery tutorial ( http://developer.android.com/guide/tutorials/views/hello-gallery.html ) but instead of simple
I followed the instructions in the Android WebView tutorial (at http://developer.android.com/resources/tutorials/views/hello-webview.html ). When I
Aloha, I've been following the guidelines here: http://developer.android.com/resources/tutorials/testing/helloandroid_test.html To create some simple test cases
I have been following this tutorial for setting up tabs in your application. http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
I'm learning about using Custom Views from the following: http://developer.android.com/guide/topics/ui/custom-components.html#modifying The description says: Class
I'm following this example: http://www.codinghorror.com/blog/2005/12/getting-started-with-indexing-service.html However, the conversion to dataset shows empty columns for
I've been following the developer.android.com page http://developer.android.com/guide/publishing/licensing.html#lc-lcc for directions on using the ServerManagedPolicy type
Ideally I want a function something like the following (this example doesn't compile): void

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.