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

  • Home
  • SEARCH
  • 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 8804307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:34:09+00:00 2026-06-14T01:34:09+00:00

Usually an Adapter will have this to optimize the performance of the listview: @Override

  • 0

Usually an Adapter will have this to optimize the performance of the listview:

 @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            System.out.println("getView " + position + " " + convertView);
            ViewHolder holder = null;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.item1, null);
                holder = new ViewHolder();
                holder.textView = (TextView)convertView.findViewById(R.id.text);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder)convertView.getTag();
            }
            holder.textView.setText(mData.get(position));
            return convertView;
        }

and view holder is:

public static class ViewHolder {
    public TextView textView;
}

But what if i have different type of rows, like 1 with an ImabeView, 1 with a CheckBox, 1 with EditText

1st thing will be:

@Override
public int getViewTypeCount() {

    return 3;
}

@Override
public int getItemViewType(int position) {

         //if something
         return 0
         //if something else
         return 1
         //if something different
         return 2
}

and in getView();

getView(int position, View convertView, ViewGroup parent){

    //if convetView == null, getItemViewType(position) and depending on the type inflate respective layout
    convertView.setTag(holder);
   //else
    holder = (ViewHolder)convertView.getTag();
}

But what about the ViewHolders, should i have 3 Different ViewHolders and depending on the type……..setTag for respective Holder?

I could find any example for something like this. Actually i haven’t seen anu ListView using more than 1 ViewHolder.

Am i doing it the right way??

Thank You

  • 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-14T01:34:11+00:00Added an answer on June 14, 2026 at 1:34 am

    There is nothing stopping you from declaring all possible views from all of ListView‘s layouts in a single ViewHolder class(so the ViewHolder will hold a reference to an ImageView, CheckBox and EditText from your example).

    In the getView method when the convertView is null you will set the views in the ViewHolder only for that type of row, all other view references in the ViewHolder will be null. When it’s time to use the views from the ViewHolder just see with which type of row your working and only get the views from the ViewHolder that belong to that row.

    You could also use three ViewHolder classes for each type of row(and set them for each particular row when you inflate it), but I think the first versions is nicer. In the end you could go either way as long as you properly implement the multiple row types mechanism.

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

Sidebar

Related Questions

I've this eventhandler: @Override protected void onListItemClick(ListView l, View v, int position, long id)
Usually when I write a PHP class I have done something like this: class
Usually when you print a string in MATLAB: disp('this will print black letters') Can
Usually when my regex patterns look like this: http://www.microsoft.com/ Then i have to escape
Usually in a django view you would do something like queryset = MyModel.objects.something() How
Usually, making a a block, you just have to hover on the <li> to
Usually, when we have to link an interface element to a field of a
I don't usually work with this type of data layer so I'm not familiar
I have a scientific application which I usually run in parallel with xargs ,
Usually I don't have problems writing assembly and testing and debugging. But then sometimes

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.