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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:45:14+00:00 2026-05-27T09:45:14+00:00

Can you please help me understand the adapter with custom data : I was

  • 0

Can you please help me understand the adapter with custom data :

I was reading a tutorial that explained that to fill a listView with a model like MyBook (with 2 variables : author and title for example), we should create a subclass of BaseAdapter and override those methods :

Here is the code :

public LivreAdapter(Context context,List<Livre> biblio) {
        inflater = LayoutInflater.from(context);
        this.biblio = biblio;
    }

    @Override
    public int getCount() {
        return biblio.size();
    }

    @Override
    public Object getItem(int position) {
        return biblio.get(position);
    }

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

    private class ViewHolder {
        TextView tvTitre;
        TextView tvAuteur;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if(convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.itemlivre, null);
            holder.tvTitre = (TextView)convertView.findViewById(R.id.tvTitre);
            holder.tvAuteur = (TextView)convertView.findViewById(R.id.tvAuteur);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvTitre.setText(biblio.get(position).getTitre());
        holder.tvAuteur.setText(biblio.get(position).getAuteur());

        return convertView;
    }

}
  1. Do we create a subclass of BaseAdapter only to display the custom data the way we want (with subtitles etc.)? Because it’s really simple to fill a listView with a String array, here we need to subclass the BaseAdapter…

  2. I cannot find those methods in the doc, so getItem will be called before getView? at the end of the method, we set “holder” to hold the text from the database, but I don’t see where we re-use this “holder”, since the only variable returned is “convertView”?

I’m looking for infos in the doc but can’t find something that help me understand exactly the process of the class.

  • 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-05-27T09:45:15+00:00Added an answer on May 27, 2026 at 9:45 am

    There are other Classes that also can be subclassed.Simple listView is useful but it cannot be used to display custom data.In order to be able to fill listView with custom data you need to use a adapter that inflates each row of listView. getItem may be used from within getView inorder to get specific entry from the list.When Adapter creates View these views are recycled so ViewHolders may be used

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

Sidebar

Related Questions

Can somebody please help me understand why my custom JComponent 'Bar', only displays when
Can someone please help me understand the following: In the previous version of NHibernate
Can someone please help be take apart the elements here and help me understand
With real examples and their use, can someone please help me understand: How to
Can someone please help me understand why this isn't working? The loading.gif appears while
Can someone please help me understand exactly what this means? <stmt> := var <ident>
With real examples and their use, can someone please help me understand: When do
Can someone please help me understand how I would write this. If i am
Java docs says the following about Set interface, can someone please help me understand
Can someone please help me understand this solution : Initialize 2D array with 81

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.