Visualización no deseada de getView

I have a listview that uses a custom layout. Inside the layout is a pin imageview. The purpose of this is to keep the same colors to the appropriate position in the list. The variable that stores which positions have pins is called int[] ping. if ping[position]==1 then set a drawing there, otherwise leave it invisible. This works when I have to refresh my list. For example, the first item will always have a red pin, second will be lite blue etc...

My problem is when I refresh my list (automatically calls the getview in my special adapter) and I didn't select the first item (Item 1 is invisible). After going through the getView function instead of an invisible item I now see the item in the highest position. (eg if I have a black and blue pin on at the same time I will see a black pin in the first spot which should be impossible because the first spot should only have a red pin). This seems like an easy fix but I can't seem to figure it out. Here is my code for the special adapter. Thanks!

EDIT The code is much shorter now because I'm putting my drawables into an array.

final public static int[]pincolors={R.drawable.pinred,R.drawable.pinliteblue,R.drawable.pinblack,R.drawable.pindarkblue,R.drawable.pingreen,R.drawable.pinlitegreen,R.drawable.pinorange,R.drawable.pinyellow,R.drawable.pinwhite,R.drawable.pinpurple};

public class SpecialAdapter extends SimpleAdapter {
    private int[] colors = new int[] { R.drawable.row_background_grey,
            R.drawable.row_background_white };

    public SpecialAdapter(Context context,
            ArrayList<HashMap<String, String>> list, int resource,
            String[] from, int[] to) {
        super(context, list, resource, from, to);


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

        View view = super.getView(position, convertView, parent);
        ImageView pincolor = (ImageView) view

        if (ping[position] == 1) {

        int colorPos = position % colors.length;
        return view;


PS. if I DO have the first item on (Red pin is showing) when I refresh, the red pin does not get changed!

preguntado el 27 de agosto de 11 a las 21:08

you could avoid a switch and put all your drawables in an array and have only one setvisible after that. It doesn t help but will be quite shorter. -

yea I can try that but its still confusing why only my first position gets changed if it is unclicked before refreshing and that it always takes the last position's color -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.