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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:26:11+00:00 2026-06-18T09:26:11+00:00

I have a list in a listview to scroll the list using this mess,

  • 0

I have a list in a “listview” to scroll the list using this mess,
grouping and the list has a header with icons.

public class MyCustomAdapter extends BaseAdapter {

private static final String ASSETS_DIR = "images/";
private static final int TYPE_HEAD = -1;
private static final int TYPE_ITEM = 0;
private static final int TYPE_SEPARATOR = 1;
private static final int TYPE_MAX_COUNT = TYPE_SEPARATOR + 1;


private Context ctx;

private ArrayList<String> mData = new ArrayList<String>();
private LayoutInflater mInflater;

private TreeSet<Integer> mSeparatorsSet = new TreeSet<Integer>();

public MyCustomAdapter(Context context) {
    this.ctx = context;
    mInflater = (LayoutInflater) ctx
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public void addItem(final String item) {
    mData.add(item);
    notifyDataSetChanged();
}

public void addSeparatorItem(final String item) {
    mData.add(item);
    mSeparatorsSet.add(mData.size() - 1);
    notifyDataSetChanged();
}

public void addHeadItem(){
    mData.add("");
    mSeparatorsSet.add(0);
    notifyDataSetChanged();
}

@Override
public int getCount() {

    return mData.size();
    //return equipos.size();
}

@Override
public String getItem(int position) {

    return mData.get(position) ;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public int getItemViewType(int position) {
    if (position==0)
        return TYPE_HEAD;

    return mSeparatorsSet.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
}

@Override
public int getViewTypeCount() {
    return TYPE_MAX_COUNT;
}

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

    ViewHolder holder = null;
    int type = getItemViewType(position);
    System.out.println("getView " + position + " " + convertView
            + " type = " + type);
    if (convertView == null) {
        holder = new ViewHolder();
        switch (type) {
        case TYPE_ITEM:
            convertView = mInflater.inflate(R.layout.list_item, null);

            holder.textView1 = (TextView) convertView.findViewById(R.id.textView1);
            holder.textView2 = (TextView) convertView.findViewById(R.id.textView2);
            holder.textView3 = (TextView) convertView.findViewById(R.id.textView3);
            holder.imageView1 = (ImageView) convertView.findViewById(R.id.imageView1);

            String[] datos = mData.get(position).split("-");

            holder.textView1.setText(String.format(" %s - %s", datos[0],datos[1]));
            holder.textView2.setText(datos[2]);
            holder.textView3.setText(datos[3]);

            String sel_bandera =  datos[4].trim() ;

            String imgFilePath = "";

            if (sel_bandera.equals("verde")){
                 imgFilePath = ASSETS_DIR + "circle_green.png" ;
            }else if (sel_bandera.equals("amarilla")){
                 imgFilePath = ASSETS_DIR + "circle_yellow.png";
            }else {
                 imgFilePath = ASSETS_DIR + "circle_red.png";
            }
            try {
                Bitmap bitmap = BitmapFactory.decodeStream(this.ctx.getResources().getAssets().open(imgFilePath));
                holder.imageView1.setImageBitmap(bitmap);
                //bandera.setImageBitmap(bitmap);
            } catch (IOException e) {
                e.printStackTrace();
            }


            break;
        case TYPE_SEPARATOR:
            convertView = mInflater.inflate(R.layout.list_group, null);
            holder.textView1 = (TextView) convertView.findViewById(R.id.textSeparator);
            holder.textView1.setText(mData.get(position));
            break;

        case TYPE_HEAD:
            convertView = mInflater.inflate(R.layout.list_head, null);

            break;
        }
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    return convertView;

}


public static class ViewHolder {

    public TextView textView1;
    public TextView textView2;
    public TextView textView3;
    public ImageView imageView1;

    public TextView getTextView1() {
        return textView1;
    }
    public void setTextView1(TextView textView1) {
        this.textView1 = textView1;
    }
    public TextView getTextView2() {
        return textView2;
    }
    public void setTextView2(TextView textView2) {
        this.textView2 = textView2;
    }
    public TextView getTextView3() {
        return textView3;
    }
    public void setTextView3(TextView textView3) {
        this.textView3 = textView3;
    }
    public ImageView getImageView1() {
        return imageView1;
    }
    public void setImageView1(ImageView imageView1) {
        this.imageView1 = imageView1;
    }

}

}

public class EquiposActivity extends ListFragment implements OnTouchListener {

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mAdapter = new MyCustomAdapter(getActivity());

            if (lista.length > 0) {
                String[] datos = lista[0].split("-");
                cabecera_grupo = datos[4];
            }

            mAdapter.addHeadItem();

            for (int i = 0; i < lista.length; i++) {

                String[] datos = lista[i].split("-");
                String grupo = datos[4];


                if (i == 0) {
                    mAdapter.addSeparatorItem(grupo.replace("_", " "));

                }

                if (!grupo.equals(cabecera_grupo)) {

                    mAdapter.addSeparatorItem(grupo.replace("_", " "));
                    cabecera_grupo = grupo;
                }

                mAdapter.addItem(String.format("%s - %s - %s - %s - %s",
                        datos[0], datos[1], datos[2], datos[3], datos[5]));

            }

            setListAdapter(mAdapter);

return super.onCreateView(inflater, container, savedInstanceState);
}

  • 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-18T09:26:13+00:00Added an answer on June 18, 2026 at 9:26 am

    I suggest you to rewrite your getView() method, because I think that you are wrongly using ViewHolder pattern. Read this: http://www.jmanzano.es/blog/?p=166
    Or just get rid of ViewHolder and code getView() without it.

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

Sidebar

Related Questions

So I have binded a List to a ListView where the List has items
I have a list of items that are displayed using a ListView from a
I have been using a Winform ListView in my project. When the list view
I have this strange problem about loading images using AsyncTask in ListView.In my ListView,
I have created a listview using LazyAdapter. When i scroll to the bottom of
I have a very simple WPF ListView that I'm using to list blocks of
Helo. I have the following requirement: I have a list (ListView or Spinner depends
I have a problem with list and listview. I started a project and added
I have a list of places in listview which i got from parsing JSON.
I have a list view as following: <ListView x:Name=lvLedger Height={Binding Path=GridHight, ElementName=ledgerList} Width={Binding Path=GridWidth,

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.