Click here to Skip to main content
15,167,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello i have made a dynamic listview..Now i have added filter in listview.m using Adapter in it.

Now i have problem:
My listview is getting filtered perfectly but while backpressing button to clear edittext listview is not getting updated..m updating my code.

here is my code:
From here m calling Getfilter method of my adater class:

list = (ListView) findViewById(;
// Pass the results into
adapter = new UpdatesAdapterList(Cardiology_updates.this,
// Set the adapter to the ListView
// adapter.notifyDataSetChanged();

et = (EditText) findViewById(;

// Capture Text in EditText
et.addTextChangedListener(new TextWatcher() {

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


    public void beforeTextChanged(CharSequence arg0, int arg1,
            int arg2, int arg3) {
        // TODO Auto-generated method stub

    public void onTextChanged(CharSequence arg0, int arg1, int arg2,
            int arg3) {
        //String text = et.getText().toString().toLowerCase(Locale.getDefault());


Here is my adapter class includes filter:

This is my filter:

	public Filter getFilter() {

	    if(valueFilter==null) {

	        valueFilter=new ValueFilter();

	    return valueFilter;
	private class ValueFilter extends Filter {
		//Filter filter = new Filter() {
	           ArrayList> filteredList;


	           protected FilterResults performFiltering(CharSequence constraint) {
	               // Holds the results of a filtering operation in values
	        	   FilterResults results=new FilterResults();
		           if(constraint!=null && constraint.length()>0){
	               filteredList= new ArrayList>();

	               //This is the search string user typed in EditText. 
	              // String searchString = constraint.toString().startsWith(prefix).toUpperCase(Locale.getDefault());

	                * Code to update the filteredList based on Search String.
	                * I'm just writing pseudo code for search, based on
	                * Cardiology_updates.UpdateTitle
	                int mCount=data.size();
	                for (int i = 0; i < mCount; i++) {
	                    HashMap obj= data.get(i);
	                    String updateTitle=obj.get(Cardiology_updates.UpdateTitle);
	                results.count = filteredList.size();
                    results.values = filteredList;
	                    // set the Filtered result to return
	                    results.count = filteredList.size();
	                    results.values = filteredList;
	            return results;
	           protected void publishResults(CharSequence constraint,
	                FilterResults results) {
	               // Has the filtered values
	               data = (ArrayList>) results.values;  
Updated 11-Nov-14 21:07pm
Dominic Burford 10-Nov-14 9:01am
Can you be more specific. You have posted a whole load of code and expect us to make sense of it all. Can you refine your question so it's easier to understand what you are asking.
vn12 10-Nov-14 9:20am
my listview is not getting updated when m clearing edittext...m updating new code with
Richard MacCutchan 10-Nov-14 10:01am
Please format your code to make it readable, as I have done for you.
vn12 11-Nov-14 6:33am
format means what should i do??
Richard MacCutchan 11-Nov-14 7:08am
Use the buttons at the top of the editor window when you edit your question. If you look at it now (use the Improve question link) you will see the <pre> tags that were added by me.
vn12 11-Nov-14 7:17am
ohk.sorry for my mistake..was aware of this..Thnx for editing it..can u give me some solution for my query?? :(
Richard MacCutchan 11-Nov-14 12:11pm
You have the line adapter.getFilter().filter(arg0); but you do not do anything with the returned Filter object.
vn12 11-Nov-14 23:59pm
Can u give some idea what should i do..will be very helpful..
vn12 12-Nov-14 2:08am
Have changed the code returned the filter also..but my problem is same..:(
Richard MacCutchan 12-Nov-14 2:59am
Well you need to apply the filter somewhere. I have not used that feature so cannot really offer much more.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900