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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:39:06+00:00 2026-06-14T02:39:06+00:00

This question has been edited for the second time: To view the original question,

  • 0

This question has been edited for the second time: To view the original question, please Scroll down to where it says “ORIGINAL QUESTION” – for any edits after that – Please scroll down to an “EDIT #” section.

EDIT TWO:

This edit is in reponse to Luksprog’s request to see where I set elements required in getView() – After checks for convertView being null or not.

Note : Please understand that this code is semi-modular.

CODE:

Holder Patterns Used:

public static class HeaderHolder
{
    public TextView textView;
}
public static class CommandHolder
{
    public TextView textView;
    public Button[] buttonHolder;
    public OnClickListener[] clickHolder;
}

getView() Method – Where the setting takes place:

    switch(type)
    {
        case 0: // Is a header
            String temp = commandLabel.replace("Section:", "");
            headerHolder.textView.setText(temp);
            break;
        case 1:// Is a command
            commandHolder.textView.setText(commandLabel);
            ArrayList<String[]> commands = commandCreator.getCommands();

            // Initially set the visibility of buttons to GONE
            for (int i = 0; i <commandHolder.buttonHolder.length; i++)
            {
                commandHolder.buttonHolder[i].setVisibility(View.GONE);
            }
            // Only show buttons based on how many commands there are
            for (int i = 0; i < commands.size(); i++)
            {
                pos = i;
                commandHolder.buttonHolder[i].setVisibility(View.VISIBLE);

                drawable_normal = commands.get(i)[1];
                drawable_pressed = commands.get(i)[1] + "_pressed";

                buttonStates = new StateListDrawable();
                buttonStates.addState(new int[]{statePressed}, ApplicationConstants.moduleImageLoader.findImageByName(drawable_pressed));
                buttonStates.addState(new int[]{-statePressed}, ApplicationConstants.moduleImageLoader.findImageByName(drawable_normal));
                buttonStates.addState(new int[]{}, ApplicationConstants.moduleImageLoader.findImageByName(drawable_normal));
                commandHolder.buttonHolder[i].setBackgroundDrawable(buttonStates);

                // Retrieve the intent and parameter from the current command
                String parameter = commands.get(i)[2];
                String intentName = commands.get(i)[0];

                if(intentName.contains("Call Phone"))
                {
                    commandHolder.clickHolder[i] = new OnClickListener()
                    {
                        public void onClick(View arg0)
                        {
                            //con.startActivity(call_phone);
                        }
                    };
                }
                else if(intentName.contains("Cell"))
                {
                    commandHolder.clickHolder[i] = new OnClickListener()
                    {
                        public void onClick(View arg0)
                        {
                            //con.startActivity(call_cell);
                        }
                    };
                }
                else if(intentName.contains("Map"))
                {
                    commandHolder.clickHolder[i] = new OnClickListener()
                    {
                        public void onClick(View arg0)
                        {
                            //con.startActivity(load_map);
                        }
                    };
                }
                else if(intentName.contains("Email"))
                {
                    commandHolder.clickHolder[i] = new OnClickListener()
                    {
                        public void onClick(View arg0)
                        {
                            //con.startActivity(send_email); 
                        }};
                }
                commandHolder.buttonHolder[i].setOnClickListener(commandHolder.clickHolder[i]);
            }
            convertView.setOnClickListener(new OnClickListener()
            {
                public void onClick(View arg0)
                {
                    Dialog dialog = new Dialog(ApplicationConstants.ref_currentActivity);
                    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                    LinearLayout listDialogBoxlayout = new ListDialogBox(con, commandType, commandLabel, commandInfo);
                    dialog.setContentView(listDialogBoxlayout);
                    dialog.setCancelable(true);
                    dialog.show();
                }
            });
            break;
    }
    return convertView;

Question : To see the problem occurring visually. Please scroll down to EDIT ONE and look at the screen shots.

If anyone has any questions, or needs clarification, please leave a comment and I will get back to you.

EDIT ONE:
Made Changes , but still the same behaviour

Here’s the new implementation of the getView() method using getItemViewType():
I do the following checks:

if(convertView == null)
{
   switch type
      case header:
        convertView = inflate a header
        headerHolder.textView = convertView.findViewById(headerTextId);
        convertView.setTag(headerHolder);
      break;
      case command:
        convertView = inflate a command
        // Use CommandHolder to initialize all the necessary elements   
        commandHolder.textView = convertView.findViewById(commandLabel);
        . 
        .
        convertView.setTag(commandHolder);
      break;
}
else
{
   switch(type)
      case header : 
         headerHolder = convertView.getTag(); 
      break;
      case command : 
         commandHolder = convertView.getTag();
         break;

}
// set the actual elements
switch(type)
   case:header
      //set all elements in header
   break;
   case: command
      //set all elements in command
   break;
 return convertView;

What’s happening:

I’m a visual person, so I thought this would help:
Here’s some screen shots:
No scrolling – Everything looks great

enter image description here

Scrolling with mouse scroll, everything still looks great

enter image description here

Scrolling by clicking on the list and dragging it down – Notice how canam is now at the bottom, where Linda should be?

enter image description here

Scrolling by clicking on the list and dragging it up – Notice how peter is at the top where canam should be?

enter image description here

List of what should be there:

  1. Address Header
  2. Canam
  3. Employees Header
  4. Dave
  5. Brent
  6. Stephen
  7. Moacir
  8. Peter
  9. Linda

Even though the views get messed up – clicking the views shows the correct dialog box pop up- As you can see above.

Here’s whats not happening:

  1. No repeating views
  2. No section headers being drawn in the wrong places
  3. No section headers being drawn as commands(which can be addresses or contacts).

I feel like I’m right there guys..
What could I have missed?


Original Question:

This is currently what I am doing: I’ve simplified the situation to really just ask my question with convertView and not possibly confuse people with the rest of my ViewCreators.

Methods that my ListViewAdapter has:

getItemViewType(...)

getViewTypeCount(...)

getView(int position, View convertView, ViewGroup parent)
{
    int type = getItemViewType(position);
    if(listItem is section)
    {    
          if(convertView == null)
          {  
              ViewGroup viewGroup = inflate a view
              Holder.textView = textview;
              viewgroup.setTag(holder);
              view = viewGroup;
          }
          else
          {
              holder = (HeaderHolder) convertView.getTag();
              view = convertView;
          }
     }
     else 
     // different layout. Complicated list item in the form: 
     //|TextView  Button1 Button2 Button3| , where buttons only appear based on 
     //a CommandCreator. If john(TextView) has a phone and email - it displays:
     // |John PhoneButton EmailButton| 
     {
           if(convertView == null)
           {
               // inflate view
               // make buttons 
               // make onclicks null
               // set different holder
               viewgroup.setTag(holder)
               view = viewgroup;
           }
           else
           {
               view = convertView;
               holder = (CommandHolder) convertView.getTag(); 
           }
           // set the buttons to show based on commands
           // set the onclick listeners to the buttons to call certain intents based on  the command
     }
     return view;
 }

}

Question:
How should I use getItemViewType and getViewTypeCount? and How do I use Viewgroups, and my current holders? Would the following work?

  getView
  {
       type = getItemViewType;
       if(convertView == null)
       {
           switch(type)
              case: header
                  convertView = inflate header view
                  intialize HeaderHolder
                  break;
              case: command
                  convertView = inflate command view
                  initialize CommandHolder
                  break;
       }
       else
       {
            switch(type)
                case: header
                       //Actually set all the HeaderHolder Stuff
                   String temp = commandLabel.replace("Section:", "");
                   holder.textView.setText(temp);
                   LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
                   holder.textView.setLayoutParams(textViewParams);
                   return view;
                               QUESTION : But how do I use Viewgroups, and my holder. and what am I returning?
                      break;
                case: command
                     Actually set all the commandHolder stuff
                     QUESTION : Same as above.
                     break;
        }
        return convertView?
  }

Here are my Handlers now:

public static class HeaderHolder
{
    public TextView textView;
}
public static class CommandHolder
{
    public TextView textView;
    public Button[] buttonHolder;
    public OnClickListener[] clickHolder;
}

Thank you for all your help in advance! and I will answer any questions you may have.

  • 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-14T02:39:07+00:00Added an answer on June 14, 2026 at 2:39 am

    About those two methods:

    • getViewTypeCount() return the number of types of layouts, 2 in your case

    • getItemViewType() based on the int parameter supplied you either return 0(for the header layout for example) or 1(for the normal row layout). This really depends on your data and how you setup the headers and normal rows in the list.

    Regarding your last edit, you probably don’t set the data on the row layout like you should, especially as you have references to those OnClickListeners. You should post the full code from this block:

    // set the actual elements
    switch(type)
       case:header
          //set all elements in header
       break;
       case: command
          //set all elements in command
       break;
    

    Here is a sample code I wrote with an example implementing multiple ViewHolders and different row layouts types(if you have problems regarding this aspect of the adapters).

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

Sidebar

Related Questions

This question has been edited to ask about a specific example as the original
Warning: This question has been heavily edited. I tried my best to guess the
NB: This question has been extensively edited to make it more relevant, for completeness
This question has been bugging me for a long time now but essentially I'm
This question has been puzzling me for a long time now. I come from
This question has been bugging me for some time. I always picture launching my
This question has been bugging me for some time. I've already developed a couple
** This question has been edited to make it simpler and more focused **
This question has been edited due to lengthy comments and updates from proposed answers.
This question has been edited for clarification: I am trying to create "pretty URLs"

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.