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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:13:52+00:00 2026-06-07T13:13:52+00:00

I am trying to provide a searchable listview. Each listitem has a name &

  • 0

I am trying to provide a searchable listview. Each listitem has a name & address text box but I only want to filter on the name. My current code does nothing, i.e no filtering occurs at all. Is there a way of setting the column to filter by?

    //class variables
private SimpleCursorAdapter mAdapter;
private EditText filterText = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

       setContentView(R.layout.add_customer_listview);

       //listViewCustomers = (ListView) findViewById(R.id.list);
       buildingListViewAdaptor();
       setListAdapter(mAdapter);

       // set up the filter
       filterText = (EditText) findViewById(R.id.search_box);
       filterText.addTextChangedListener(filterTextWatcher);

}


private TextWatcher filterTextWatcher = new TextWatcher() {


    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
    }

    public void onTextChanged(CharSequence s, int start, int before,
            int count) {
        mAdapter.getFilter().filter(s);
        Log.d(GlobalTools.ErrorCodes.INFO, "Searchtext="  + s.toString());
    }

    public void afterTextChanged(Editable arg0) {
        // TODO Auto-generated method stub

    }

};

private void buildingListViewAdaptor(){

    //1. Get the data
    CustomerLocationDataHandler clDataHandler = new CustomerLocationDataHandler(getContentResolver());
    Cursor cursor = clDataHandler.allCustomerLocations();
    clDataHandler=null;

    //2. Build the adaptor
    mAdapter = new SimpleCursorAdapter(this, 
            R.layout.list_item_custom_font, // was list_item_custom_font
            cursor,  
            new String[]{MyobiliseData.Columns_CustomerLocations.CUSTOMER_NAME,MyobiliseData.Columns_CustomerLocations.CITY},
            new int[] {R.id.text1,R.id.text2}
            );

}
  • 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-07T13:13:54+00:00Added an answer on June 7, 2026 at 1:13 pm

    To achieve this I needed to re-query the database each time the user typed in the search box. I have included the working code here:

    public class AddCustomerActivity extends ListActivity{
    
    //constants
    public static final String B4ME = "B4ME";  //Used when passing a boolean to this activity
    
    // dialog constants
    private static final int DIALOG_CHECKINSERT = 0;
    
    
    //class variables
    private SimpleCursorAdapter mAdapter;
    private EditText filterText = null;
    private boolean mInsertB4;   //if false ->means insert after
    private Long mRunDetailID;
    private Long mCustomerLocationId;
    private int mSelectedItemPosition;
    private long mSelectedItemId;
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    
           setContentView(R.layout.add_customer_listview);
           readVariablesPassedToThis();
    
           //listViewCustomers = (ListView) findViewById(R.id.list);
           buildingListViewAdaptor();
           setListAdapter(mAdapter);
    
    
           // set up the filter
           filterText = (EditText) findViewById(R.id.search_box);
           filterText.addTextChangedListener(filterTextWatcher);
    
           mAdapter.setFilterQueryProvider(new FilterQueryProvider() {
               public Cursor runQuery(CharSequence constraint) {
    
                   return filterRefresh(constraint);
               }
           });
    
    }
    
    
    private TextWatcher filterTextWatcher = new TextWatcher() {
    
    
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }
    
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            mAdapter.getFilter().filter(s);
        }
    
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
    
        }
    
    };
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    
        super.onListItemClick(l, v, position, id);
        mSelectedItemPosition = position;
        mSelectedItemId = id;
        Log.d(GlobalTools.ErrorCodes.INFO, "Selected ItemPosition=" + mSelectedItemPosition + " and itemid ="+mSelectedItemId);
        showDialog(DIALOG_CHECKINSERT);
    
    }
    
    
    private void buildingListViewAdaptor(){
    
        //2. Build the adaptor
        mAdapter = new SimpleCursorAdapter(this, 
                R.layout.list_item_custom_font, // was list_item_custom_font
                filterRefresh(null),  
                new String[]{MyobiliseData.Columns_CustomerLocations.CUSTOMER_NAME,MyobiliseData.Columns_CustomerLocations.CITY},
                new int[] {R.id.text1,R.id.text2}
                );
    
    }
    
    private Cursor filterRefresh(CharSequence constraint){
        //1. Get the data
        CustomerLocationDataHandler clDataHandler = new CustomerLocationDataHandler(getContentResolver());
        Cursor cursor = clDataHandler.customerLocationsFilteredOn(constraint);
        clDataHandler=null;
        return cursor;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to refactor code to provide clean association A GAME has a HOME_TEAM and
I'm trying to use ThreadLocal to provide thread safety to pre-existing non-thread-safe classes, but
I'm trying to provide two classes to my users - one that is read-only
I am trying to provide undo functionality after a record has been deleted. To
i am trying to provide client side validation for password using jquery, but the
i'm trying to provide different static initializations for classes in a hierarchy, but when
I am trying to provide my own labelFunction for a CategoryAxis programatically but am
Im trying to provide gzip compression using varnish cache. But when I set content-encoding
I'm trying to provide a form to create a message for each feature on
I'm trying to provide a link to the attachment of a note through the

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.