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 8836757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:34:04+00:00 2026-06-14T09:34:04+00:00

I have a listView with about 30 items in it and have added a

  • 0

I have a listView with about 30 items in it and have added a search function to it via an editText. When I type ‘a’ in the textfield everything that starts with an ‘a’ shows up on the list but when I type another letter the list disappears even tho the list contains an item with ‘a’ + the other letter i typed.

Another thing that confuses me is that there is an item in the list called IWU Trading and thats the only item I can search for, means that if I type ‘I’ + ‘W’ the item shows up in the listView. But if I type ‘a’ + ‘r’ an item that is named ‘art’ dosent show up.

My question(s).
How can I do to make this search function work?
Why does it act like it does?

My XML

    <EditText
    android:id="@+id/searchEditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/selectCustomerTextView"
    android:layout_marginTop="20dp"
    android:hint="@string/typeToSearch"
    android:ems="10"
    android:imeOptions="actionDone"
    android:inputType="textNoSuggestions"/>


<ListView
    android:id="@+id/list_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/nextButton"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/searchEditText" 
    android:choiceMode="singleChoice"
    android:dividerHeight="5dp" >
</ListView>

My code:

    private ArrayAdapter<Customer> _oldAdapter = null;

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate( savedInstanceState );
    setContentView(R.layout.activity_customer_pick);
    EditText searchText = (EditText) findViewById(R.id.searchEditText);
    ListView listView = (ListView) findViewById(R.id.list_view);
    listView.setClickable(true);

    searchText.addTextChangedListener(filterTextWatcher);

    _oldAdapter = _phoneDAL.BindValues(this);

    listView.setAdapter(_oldAdapter);

    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
              String s = _oldAdapter.getItem(arg2).toString();
              _listViewPostion = arg2;

              Toast.makeText(CustomerPick.this, "Du valde: " + s, arg2).show();
        }
    });
}

The search method:

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) {
        ArrayAdapter<Customer> _adapter = new ArrayAdapter<Customer>(CustomerPick.this, android.R.layout.simple_list_item_single_choice, new ArrayList<Customer>());

        ListView listView = (ListView) findViewById(R.id.list_view);

        int textLength = s.length();

        if(textLength == 0){
            listView.setAdapter(_oldAdapter);
            return;
        }
                for (int i = 0; i < listView.getAdapter().getCount(); i++)
                {
                    String word = _oldAdapter.getItem(i).getCustName().toLowerCase();
                    if (textLength <= word.length())
                    {
                        if(s.toString().equalsIgnoreCase(word.substring(0, textLength)))
                        {
                            _adapter.add(_oldAdapter.getItem(i));
                        }
                    }
                }
                listView.setAdapter(_adapter);
    }
};

}

My CustomerClass (private ArrayAdapter _oldAdapter = null;)

public class Customer {
private final int _custNumber;
private final String _custName;

public Customer(int custNumber, String custName){
    _custNumber = custNumber;
    _custName = custName;
}

public int getCustNumber() {
    return _custNumber;
}


public String getCustName() {
    return _custName;
}


@Override
public String toString(){
    return _custName;
}

}

  • 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-06-14T09:34:06+00:00Added an answer on June 14, 2026 at 9:34 am

    Solved the problem by adding:

    ListView listView = (ListView) findViewById(R.id.list_view);
    ((Filterable) listView.getAdapter()).getFilter().filter(s);
    

    into the afterTextChanged method of the TextWatcher(after reading Luksprog’s comment).

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

Sidebar

Related Questions

I have a ListView that has 3 GridViewColumns and about 10 items. The third
I have a listView, it has about 100 items. Currently I have this code:
I have a program that runs the checked items from a ListView control. These
I have created a page with horizontal layout listview with enough items added to
So I have a ListView with an upper limit of about 1000 items. I
I have ListView with about 30 items. When I click on an item, some
I have a ListView with about 400 entries. I need to search thru it
I have listview control.There is an option to remove selected items.After the user removes
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton
I have ListView that uses a GridView to display several columns of data. Two

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.