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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:03:00+00:00 2026-06-04T08:03:00+00:00

I have a Product Class, Which has three fields:- id name price In my

  • 0

I have a Product Class, Which has three fields:-

  1. id
  2. name
  3. price

In my code I create a List<Product> productList = Collections.synchronizedList(new ArrayList<Product>());

This product list is used to create a ArrayAdapter<Product> adapter = ArrayAdapter<Product>(), I fill the productList in a separate thread and adapter is notified accordingly. It is working absolutely fine.

Now,

  1. I want to change the color of the some specific products (say for price < 1000).
  2. Each row of ListView should contain 4 elements product image,name, desc and price.
  3. When User clicks the Product, in a context menu options i.e. buy Product, View Product should be displayed.

I have read few blogs and threads related to that. Still I cant decide where to begin, I read about the customization of the ArrayAdapter, overriding getView(), custom list filters etc. Which way will be the best for my requirement… in other words How can custom adapters and list filters benefit 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-04T08:03:02+00:00Added an answer on June 4, 2026 at 8:03 am

    You should extend BaseAdapter and provide your own layout for each item (getView()). Don’t forget to manage the view recycling and maybe use the ViewHolder paradigm.

    EDIT

    I didn’t use a lot the ListAdpater, because it binds to a ListView only. Sometimes I need an adapter for a GridView, and the BaseAdapter gives me enough freedom for all use cases.

    Example of BaseAdapter:

    public class FanAdapter extends BaseAdapter {
    
        private List<Fan> mFans;
        private Activity mContext;
    
        public FanAdapter(Activity context, List<Fan> fans) {
            mContext = context;
            mFans = fans;
        }
    
        private class ViewHolder {
    
            public ImageView image;
            public TextView firstName;
            public TextView lastName;   
        }
    
        @Override
        public View getView(int position, View view, ViewGroup container) {
            if (view == null) {
                view = LayoutInflater.from(mContext).inflate(R.layout.fan_item, container, false);
            }
    
            ViewHolder viewHolder = (ViewHolder) view.getTag();
            if(viewHolder == null){
                viewHolder = new ViewHolder();
                viewHolder.image = (ImageView) view.findViewById(R.id.image);
                viewHolder.firstName = (TextView) view.findViewById(R.id.firstname);
                viewHolder.lastName = (TextView) view.findViewById(R.id.lastname);
                view.setTag(viewHolder);
            }
    
            // setting here values to the fields of my items from my fan object
            viewHolder.firstName.setText(fan.getFirstName());
            (...)
    
    
            return view;
        }
    
        @Override
        public int getCount() {
            if (mFans != null) {
                return mFans.size();
            } else {
                return 0;
            }
        }
    
        @Override
        public Object getItem(int position) {
            return mFans.get(position);
        }
    
        @Override
        public long getItemId(int position) {
            return position;
        }
    }
    

    You can use it with an Activity containing a ListView or a ListActivity (having in its layout a ListView with a special id):

    <ListView
            android:id="@id/android:list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:cacheColorHint="@android:color/transparent" />
    

    This way, your ListActivity that will inflate the view will be able to make a findViewById() call and getListView() will return this internal listView. It’s a small hack, you can put your own listView with another id and make the findViewById() yourself. For The ListActivity, there’s another hack: if the ListActivity finds an empty view with again a special id, it will be shown when the list is empty:

    <include
        android:id="@+id/empty"
        layout="@layout/empty"
        android:visibility="gone"
        android:layout_gravity="center" />
    

    Then on your listView, whether you used an Activity or ListActivity, you can set your adapter on the ListView:

    getListView().setAdapter(new FanAdapter(this, myFanDataArray)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Grails domain class: class Product { String name Float basePrice
In Django, I have two models: class Product(models.Model): name = models.CharField(max_length = 50) categories
I have a Products:List<Product> class. I'd like to make it so that every time
I have a product entity which has several classes (each product type has different
Suppose I have public class Product: Entity { public IList<Item> Items { get; set;
I have a view model that contains a Product class type and an IEnumerable<
I have in my javascript these 2 functions classes: // product class function Product()
Simple question on best practice. Say I have: public class Product { public string
I have the following .Net class: public class Product { public int ID {get;set;}
I have a viewmodel that contains a product and SelectList of categories. public class

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.