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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:55:51+00:00 2026-06-13T20:55:51+00:00

I have a Custom Listview. I have to display data from the webserver. I

  • 0

I have a Custom Listview. I have to display data from the webserver. I need to implement search based on input from EditText. Each row in ListView Contains Image, Title and Message.
Image Changes based on response from WebServer. Have a Look at the code.

class CustomListView extends ArrayAdapter {

Context context;
LayoutInflater mInflater;
ArrayList<PostData> mPostingData = null;
private Bitmap mIcon1;
private Bitmap mIcon2;
private Bitmap mIcon3;
PostData mp ;

public  CustomListView(Context c)
{
     super(c, 0);
    mInflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mIcon1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.text_icon);
    mIcon2 = BitmapFactory.decodeResource(c.getResources(), R.drawable.image_icon);
    mIcon3 = BitmapFactory.decodeResource(c.getResources(), R.drawable.video_icon);
}   

public int getCount() {
    // TODO Auto-generated method stub
    if(mPostingData!=null){
        return mPostingData.size();
    }else{
        return 0;
    }
}

 public void setData(ArrayList<PostData> mPpst) {

    mPostingData = mPpst;
}


public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return arg0;
}

public View getView(int position, View convertView, ViewGroup parent) {
     ViewHolder holder;
    ///int type = getItemViewType(arg0);
     Log.i("Aru","get View");
    if(mPostingData == null ){

        return null;
    }

            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.listviewimg, null);
                convertView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));
                // Creates a ViewHolder and store references to the two children views
                // we want to bind data to.
                holder = new ViewHolder();
                holder.ll=(LinearLayout) convertView.findViewById(R.id.lvid);
                holder.text = (TextView) convertView.findViewById(R.id.texttitle);
                holder.text2 = (TextView) convertView.findViewById(R.id.tvst);
                holder.icon = (ImageView) convertView.findViewById(R.id.llimage);

                convertView.setTag(holder);
            } else {

                holder = (ViewHolder) convertView.getTag();
            }

            mp = mPostingData.get(position);

            String title = mp.mType;

            if(mp.mTitle!=null && Name.equals(mp.mPostedBy )){
                title = mp.mTitle+" "+title;
                //holder.text.setBackgroundColor(Color.WHITE);
                holder.ll.setBackgroundResource(R.drawable.listbkgme);
                holder.text.setText(title);
            }
            else if(mp.mTitle!=null && Name!=mp.mPostedBy)
            {
                title = mp.mTitle+" "+title;
           holder.text.setText(title);
            }


            if(mp.mMessage!=null && Name.equals(mp.mPostedBy )){

                holder.ll.setBackgroundResource(R.drawable.listbkgme);
                holder.text2.setText(mp.mMessage);

            }
            else if(mp.mMessage!=null && Name!=(mp.mPostedBy))
            {
                holder.text2.setText(mp.mMessage);
            }


            if(mp.mImageUrl!=null ){

                holder.icon.setImageBitmap(mIcon2);
            }else if(mp.mVideoUrl!=null){
                holder.icon.setImageBitmap(mIcon3);
            }else{
                holder.icon.setImageBitmap(mIcon1);
            }
       return convertView;
}
 class ViewHolder {
    TextView text;
    TextView text2;
    ImageView icon;
    LinearLayout ll;
}
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

}

Post Data Class

 class PostData {
String mID; 
String mPostedBy;
String mTitle;
String mMessage;
String mImageUrl;
String mVideoUrl;
String mType ;
boolean me=false;

}

Sorting Based on Title. How can i search the listview based on Title??

    search= (EditText) findViewById(R.id.searchbox);
     search.addTextChangedListener(new TextWatcher() {

         public void onTextChanged(CharSequence s, int start, int before, int count) {
             final String searchString=search.getText().toString();
               int textLength=searchString.length();



               Collections.sort(
                       mTempPost, 
                       new Comparator<PostData>() 
                       {



                        public int compare(PostData lhs, PostData rhs) {

                             System.out.println("........................"+lhs.mTitle+" "+rhs.mTitle);

                              return lhs.mTitle.compareTo(rhs.mTitle);
                        }


                       }
                     );

                         mCustomListView.notifyDataSetChanged();

         }

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


           }

           public void afterTextChanged(Editable s) {

              // mCustomListView.notifyDataSetChanged();
           }
          });
  • 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-13T20:55:52+00:00Added an answer on June 13, 2026 at 8:55 pm

    You want your adapter to implement Filterable. Then override getFilter to perform the search

    @Override
    public Filter getFilter() {
        return new Filter() {
            @Override
            protected void publishResults(CharSequence constraint, FilterResults results) {
                if (results != null && results.count >= 0) {
                    setData(results.values);
                } else {
                    setData(mPostingData);
                }
    
                notifyDataSetInvalidated();
            }
    
            @Override
            protected FilterResults performFiltering(CharSequence constraint) {
                FilterResults result = new FilterResults();
                if (!TextUtils.isEmpty(constraint)) {
                    constraint = constraint.toString().toLowerCase();
                    ArrayList<PostData> currentItems = new ArrayList<PostData>();
                    ArrayList<PostData> foundItems = new ArrayList<PostData>();
    
                    currentItems.addAll(mPostingData);
    
                    for (PostData post: currentItems){
                        // Search for the items here. If we get a match, add to the list
                        if (post.mType.toLowerCase().contains(constraint)) {
                            foundItems.add(m);
                        } else if .... {
                        }
                    }
    
                    result.count = foundItems.size();
                    result.values = foundItems;
                } else {
                    result.count = -1;
                }
    
                return result;
            }
        };
    }
    

    You would then call the search from the activity with adapter.getFilter().filter(“Search Query”).

    This will replace the list of items in your listview with the search results too.

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

Sidebar

Related Questions

I have created a custom ArrayAdapter to display data within ListView items from an
I have created a custom listview using adapter. Each row of the list view
I have a ListView which uses a custom adapter to display rows of data.
I have a listview which I am populating with a custom SimpleCursorAdapter, each row
I have a custom listview, i successfully parse the data into a list but
I have a custom listview which display an image, textview and radio button. I
I have implemented an application with Custom base adapter for display data in list
I have a custom listview and I am using a custom listadapter to display
I am needing help populating data from a database into a custom ListView. I
I have a custom ListView which contains one TextView (Of numbers) and one EditText

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.