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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:30:11+00:00 2026-06-11T20:30:11+00:00

Now i want to make filter but i really don’t know how to do

  • 0

Now i want to make filter but i really don’t know how to do it. I’ve read some tutorials and tried but it still does not work. Please help me!
i want to implement the search functionality.

code of class apdater:

public class PlaceAdapter extends BaseAdapter {
private static ArrayList<Place> searchArrayList;

private LayoutInflater mInflater;

public PlaceAdapter(Context context, ArrayList<Place> results) {
    searchArrayList = results;
    mInflater = LayoutInflater.from(context);
}

public int getCount() {
    return searchArrayList.size();
}

public Object getItem(int position) {
    return searchArrayList.get(position);
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.row, null);
        holder = new ViewHolder();
        holder.txtName = (TextView) convertView
                .findViewById(R.id.label_place);
        holder.txtAddress = (TextView) convertView
                .findViewById(R.id.label_address);
        holder.txtPhone = (TextView) convertView
                .findViewById(R.id.label_distance);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.txtName.setText(searchArrayList.get(position).getName());
    holder.txtAddress.setText(searchArrayList.get(position).getAddress());
    holder.txtPhone.setText(searchArrayList.get(position).getPhone());

    return convertView;
}

static class ViewHolder {
    TextView txtName;
    TextView txtAddress;
    TextView txtPhone;
}

}

code of class activity

public class ServiceDetail extends Activity {

private String DB_NAME = "Danang Travel.sqlite";
private PlaceAdapter adapter = null;

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

    final ArrayList<Place> searchResults = GetSearchResults();

    final EditText filterEditText = (EditText) findViewById(R.id.filter_text);
    final ListView lvPlace = (ListView) findViewById(R.id.listView1);

    adapter = new PlaceAdapter(this, searchResults);
    lvPlace.setAdapter(adapter);
    lvPlace.setTextFilterEnabled(true);

    // Set Focus*****************************************
    lvPlace.setFocusableInTouchMode(true);
    lvPlace.requestFocus();
    lvPlace.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View arg0, boolean arg1) {
            // TODO Auto-generated method stub
            // arg0.setBackgroundColor(arg1 ? Color.GRAY : Color.BLACK);
            // lvPlace.setItemsCanFocus(true);
        }

    });

    // lvPlace.setClickable(true);

    /******************************************************/
    // filter search
    filterEditText.addTextChangedListener(new TextWatcher() {

        public void onTextChanged(CharSequence cs, int arg1, int arg2,
                int arg3) {
            // When user changed the Text
            //ServiceDetail.this.adapter.getFilter().filter(cs);


        }

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

        }

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

    lvPlace.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> a, View v, int position,
                long id) {
            Object o = lvPlace.getItemAtPosition(position);
            Place fullObject = (Place) o;
            Toast toast = Toast.makeText(ServiceDetail.this,
                    "You have chosen: " + " " + fullObject.getName(),
                    Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
            toast.show();
        }
    });

}

private ArrayList<Place> GetSearchResults() {
    ArrayList<Place> results = new ArrayList<Place>();

    SQLiteDatabase DB = null;
    Intent t = getIntent();
    Bundle extra = t.getExtras();
    String temp = extra.getString("k");
    try {
        DB = this.openOrCreateDatabase(DB_NAME, MODE_PRIVATE, null);

        Cursor c = DB.rawQuery(
                "SELECT Name,Address,TypeID FROM ServiceDetail Where SerID = '"
                        + temp + "' ORDER BY Name", null);

        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            Place k = new Place();
            // The Cursor is now set to the right position
            String n = c.getString(c.getColumnIndex("Name"));
            String a = c.getString(c.getColumnIndex("Address"));
            String p = c.getString(c.getColumnIndex("TypeID"));

            k.setName(n);
            k.setAddress(a);
            k.setPhone(p);
            results.add(k);
        }

    } catch (SQLiteException se) {
        Log.e(getClass().getSimpleName(),
                "Could not create or Open the database");

    } finally {
        DB.close();
    }

    return results;
}

}

Now i want to make filter but i really don’t know how to do it. I’ve read some tutorials and tried but it still does not work. Please help me!

  • 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-11T20:30:12+00:00Added an answer on June 11, 2026 at 8:30 pm

    Here you go 🙂

        //Firstly here is your edittext on which you want to filter
        EditTextfilterText = (EditText) findViewById(R.id.search_box);
        filterText.clearComposingText();
        //Give the edittext the watcher as a text listener
        filterText.addTextChangedListener(filterTextWatcher);
    
    //This will listen to key events such as you entering something inside the edit text
    private TextWatcher filterTextWatcher = new TextWatcher() {
    
    
        public void afterTextChanged(Editable s) {
            //Called after text changed
        }
    
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }
    
        //Called each time you enter something into the edittext to filter your list or whatever
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
    
                    //Adapter creating code
                          //......
                    //Filter calling code
                    adapter.getFilter().filter(s, new FilterListener() {
                    @Override
                    public void onFilterComplete(int count) {
                        //Just for fun do something here once filtering is done
                    }
                });
    
    
            }
        }
    
    };
    

    Now inside your custom adapter you would have the following:


     public Filter getFilter() {
    
            filter = new DrugListFilter();
    
        return filter;
    }
    
    
    private class MyFilterName extends Filter{
    
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults retval = new FilterResults();
                        ArrayList<something> filt = new ArrayList<something>();
    
                        //... Some code to filter your current Adapter data by the constaint
                        //Pass the results to retval
                        retval.count = filt.size();
                        retval.values = filt;
                           }
                        //return retval
                    return retval;
            }
    
        //This is called once performFiltering is done
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            filteredItems.clear();
                        //This is your array of filtered items
            filteredItems.addAll((ArrayList)results.values);
            doneFilter = true;
                        //Notify the dataset that it needs to update
            notifyDataSetChanged();
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a iPhone app but I need to now how you
I want to make a judge, if checkbox value = 2, selected. But now
I've made a database using phpMyAdmin , now I want to make a register
I've created an ics file using DDay iCal library. Now I want to make
I have this json string: $row['medium'] = {\medium\:13|17|1|14, \medium_sub\:21}; now I want to make
i am done with my iphone application.Now i just want to make a binary
I want to make an ad banner. Right now i have an imagebutton that
i want to make a php app that let people submit photos/videos/sounds Now, everything
I make extensive use of Struts2 in my application. Now I want to add
i want to reload ViewdidLoad in a method But now want to call again

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.