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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:08:42+00:00 2026-06-11T04:08:42+00:00

i’m new to android. I’m just trying to make one simple search functionality for

  • 0

i’m new to android. I’m just trying to make one simple search functionality for my app. My app consists one ListView one EditText and one Button for search. My ListView contents are listed from database using custom adapter which is extends BaseAdapter

Now, what i’m trying to do is, i want to search any records from ListView For example, if i’ve some records like

Optimization, Operations, Data Mining, Computer Ethics, Computer Architecture and etc…

So, when i type some record name like op

The listview should listed the records which is started from op... I’ve referred something for this, from i got addTextChangedListener But, i don’t know how to do this?

And, Can we do this same functionality with click of button

Has anyone having any idea on this? Thanks in advance.

  • 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-11T04:08:43+00:00Added an answer on June 11, 2026 at 4:08 am

    I had asked a similar kinda question a while back. Here: Filtering a ListView with Baseadapter filters text not images. Although, my specific question concerned a GridView, the concept (and the code) can be substituted for a ListView.

    NOTE: This will be a lengthy post but I think necessary for the sake of completeness (I am leaving out the imports though)

    The main activity (Friends.java)

    public class Friends extends SherlockActivity {
    
        // BUNDLE OBJECT TO GET DATA FROM EARLIER ACTIVITY
        Bundle extras;
    
        // INITIAL ALBUM ID AND NAME
        String initialUserID;
    
        // THE GRIDVIEW
        GridView gridOfFriends;
    
        // THE ADAPTER
        FriendsAdapter adapter;
    
        // ARRAYLIST TO HOLD DATA
        ArrayList<getFriends> arrFriends;
    
        // LINEARLAYOUT TO SHOW THE FOOTER PROGRESS BAR
        LinearLayout linlaProgressBar;
    
        // THE EDITTEXT TO FILTER USERS
        EditText filterText;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.friends_grid_list);
    
            extras = getIntent().getExtras();
    
            if (extras.containsKey("USER_ID"))  {
                initialUserID = extras.getString("USER_ID");
            } else {
                Toast.makeText(
                        getApplicationContext(), 
                        "There was a problem getting your Friends Data. Please hit the back button and try again.", 
                        Toast.LENGTH_SHORT).show();
            }
    
            ActionBar actionBar = getSupportActionBar();
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowHomeEnabled(true);
            actionBar.setDisplayShowTitleEnabled(true);
            actionBar.setTitle("Your Friends");
    
            // CAST THE GRIDVIEW
            gridOfFriends = (GridView) findViewById(R.id.gridFriends);
    
            // INSTANTIATE THE ARRAYLIST
            arrFriends = new ArrayList<getFriends>();
    
            // CAST THE ADAPTER
            adapter = new FriendsAdapter(Friends.this, arrFriends);
    
            // CAST THE LINEARLAYOUT THAT HOLDS THE PROGRESS BAR
            linlaProgressBar = (LinearLayout) findViewById(R.id.linlaProgressBar);
            linlaProgressBar.setVisibility(View.GONE);
    
            // GET THE LOGGED IN USERS FRIENDS DATA
            if (initialUserID != null)  {
                new getFriendsData().execute();
            } else {
                Toast.makeText(
                        getApplicationContext(), 
                        "There was a problem getting your Friends Data. Please hit the back button and try again.", 
                        Toast.LENGTH_SHORT).show();
            }
    
            // CAST THE EDITTEXT AND SETUP FILTERING
            filterText = (EditText) findViewById(R.id.editFilterList);
            filterText.addTextChangedListener(filterTextWatcher);
        }
    
        private class getFriendsData extends AsyncTask<Void, Void, Void>    {
    
            @Override
            protected void onPreExecute() {
    
                // SHOW THE BOTTOM PROGRESS BAR (SPINNER) WHILE LOADING THE FRIENDS LIST
                linlaProgressBar.setVisibility(View.VISIBLE);
            }
    
            @Override
            protected Void doInBackground(Void... params) {
    
                try {
                    String query = 
                            "SELECT name, uid, pic_big " +
                            "FROM user " +
                            "WHERE uid in " +
                            "(SELECT uid2 FROM friend WHERE uid1=me()) " +
                            "order by name";
                    Bundle paramGetFriendsList = new Bundle();
                    paramGetFriendsList.putString("method", "fql.query");
                    paramGetFriendsList.putString("query", query);
    
                    String resultFriendsList = Utility.mFacebook.request(paramGetFriendsList);
    
                    JSONArray JAFriends = new JSONArray(resultFriendsList);
    
                    getFriends friends;
    
                    if (JAFriends.length() == 0)    {
    
                    } else {
                        for (int i = 0; i < JAFriends.length(); i++) {
                            JSONObject JOFriends = JAFriends.getJSONObject(i);
    
                            friends = new getFriends();
    
                            // SET FRIENDS ID
                            if (JOFriends.has("uid"))   {
                                friends.setFriendID(JOFriends.getString("uid"));
                            } else {
                                friends.setFriendID(null);
                            }
    
                            // SET FRIENDS NAME
                            if (JOFriends.has("name"))  {
                                friends.setFriendName(JOFriends.getString("name"));
                            } else {
                                friends.setFriendName(null);
                            }
    
                            // SET FRIENDS PROFILE PICTURE
                            if (JOFriends.has("pic_big"))   {
                                friends.setFriendProfile(JOFriends.getString("pic_big"));
                            } else {
                                friends.setFriendProfile(null);
                            }
    
                            arrFriends.add(friends);
    
                        }
                    }
    
                } catch (Exception e) {
                    e.printStackTrace();
                }
    
                return null;
            }
    
            @Override
            protected void onPostExecute(Void result) {
    
                // SET THE ADAPTER TO THE GRIDVIEW
                gridOfFriends.setAdapter(adapter);
    
                // HIDE THE BOTTOM PROGRESS BAR (SPINNER) AFTER LOADING THE FRIENDS LIST
                linlaProgressBar.setVisibility(View.GONE);
            }
    
        }
    
        private TextWatcher filterTextWatcher = new TextWatcher() {
    
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
    
                adapter.getFilter().filter(s.toString().toLowerCase());
                adapter.notifyDataSetChanged();
            }
    
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
            }
    
            @Override
            public void afterTextChanged(Editable s) {
    
            }
        };
    }
    

    The getFriends.java class for the ArrayList:

    public class getFriends {
    
        String friendID;
        String friendName;
        String friendProfile;
    
        // SET FRIENDS ID
        public void setFriendID(String friendID) {
            this.friendID = friendID;
        }
    
        // GET FRIENDS ID
        public String getFriendID() {
            return friendID;
        }
    
        // SET FRIENDS NAME
        public void setFriendName(String friendName) {
            this.friendName = friendName;
        }
    
        // GET FRIENDS NAME
        public String getFriendName() {
            return friendName;
        }
    
        // SET FRIENDS PROFILE
        public void setFriendProfile(String friendProfile) {
            this.friendProfile = friendProfile;
        }
    
        // GET FRIENDS PROFILE
        public String getFriendProfile() {
            return friendProfile;
        }
    }
    

    And finally, the adapter class (FriendsAdapter.java)

    public class FriendsAdapter extends BaseAdapter implements Filterable {
    
        ProgressDialog dialog;
    
        Activity activity;
    
        LayoutInflater inflater = null;
        ImageLoader imageLoader;
    
        ArrayList<getFriends> arrayFriends;
        List<getFriends> mOriginalNames;
    
        FriendsAdapter(Activity a, ArrayList<getFriends> arrFriends) {
    
            activity = a;
    
            arrayFriends = arrFriends;
    
            inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            imageLoader = new ImageLoader(activity.getApplicationContext());
        }
    
        public int getCount() {
            return arrayFriends.size();
        }
    
        public Object getItem(int position) {
            return arrayFriends.get(position);
        }
    
        public long getItemId(int position) {
            return position;
        }
    
        @Override
        public void notifyDataSetChanged() {
            super.notifyDataSetChanged();
        }
    
        public View getView(final int position, View convertView, ViewGroup parent) {
            View vi = convertView;
            if (convertView == null)
                vi = inflater.inflate(R.layout.friends_grid_items, null);
    
            ImageView imgProfilePicture = (ImageView) vi.findViewById(R.id.imgProfilePicture);
            TextView txtUserName = (TextView) vi.findViewById(R.id.txtUserName);
            FrameLayout mainContainer = (FrameLayout) vi.findViewById(R.id.mainContainer);
    
    
            txtUserName.setText(arrayFriends.get(position).getFriendName());
    
            if (arrayFriends.get(position).getFriendProfile() != null) {
                imageLoader.DisplayImage(arrayFriends.get(position).getFriendProfile(),imgProfilePicture);
            } else if (arrayFriends.get(position).getFriendProfile() == null) {
                imgProfilePicture.setVisibility(View.GONE);
            }
    
            mainContainer.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    Intent showFriendsProfile = new Intent(activity.getApplicationContext(), UserProfileNew.class);
                    showFriendsProfile.putExtra("USER_ID", arrayFriends.get(position).getFriendID());
                    showFriendsProfile.putExtra("NAME", arrayFriends.get(position).getFriendName());
                    activity.startActivity(showFriendsProfile);
                }
            });
    
            return vi;
        }
    
        @Override
        public Filter getFilter() {
    
            Filter filter = new Filter() {
    
                @SuppressWarnings("unchecked")
                @Override
                protected void publishResults(CharSequence constraint,
                        FilterResults results) {
    
                    arrayFriends = (ArrayList<getFriends>) results.values;
                    notifyDataSetChanged();
                }
    
                @Override
                protected FilterResults performFiltering(CharSequence constraint) {
    
                    FilterResults results = new FilterResults();
                    ArrayList<getFriends> FilteredArrayNames = new ArrayList<getFriends>();
    
                    if (mOriginalNames == null) {
                        mOriginalNames = new ArrayList<getFriends>(arrayFriends);
                    }
                    if (constraint == null || constraint.length() == 0) {
                        results.count = mOriginalNames.size();
                        results.values = mOriginalNames;
                    } else {
                        constraint = constraint.toString().toLowerCase();
                        for (int i = 0; i < mOriginalNames.size(); i++) {
                            getFriends dataNames = mOriginalNames.get(i);
                            if (dataNames.getFriendName().toLowerCase()
                                    .contains(constraint.toString())) {
                                FilteredArrayNames.add(dataNames);
                            }
                        }
    
                        results.count = FilteredArrayNames.size();
                        // System.out.println(results.count);
    
                        results.values = FilteredArrayNames;
                        // Log.e("VALUES", results.values.toString());
                    }
    
                    return results;
                }
            };
    
            return filter;
        }
    }
    

    You can use the concept here and substitute for your ListView. I have used this elsewhere for a ListView and works as it should. Unfortunately, I cannot give that code away on a public fora. Hope this helps you though. Again, a very lengthy post no doubt, but necessary I believe.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

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.