duplicated in arrayadapter android

1

I'm making my own adapter to put in a listview, it visually shows everything right. Each line of the list view, consists of an image, a text and 2 spinners ....

When it is shown, it has apparently been great, and each elemet has been assigned a different photo ....

where is the problem? because when I start filling in the text of element 1, I automatically fill in the 6, if I fill in 2, the 7 tb is autocompleta .... I do not understand what happens, could you help me ??

    package com.example.oftecnica2.pruebaaudiobus;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by OFTECNICA2 on 12/04/2016.
 */
public class Adaptador extends ArrayAdapter{


    public Adaptador(Context context, String[] objects) {
        super(context,0,objects);
    }


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

        LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View listItemView=convertView;
        if (null==convertView){

           listItemView=inflater.inflate(R.layout.layoutcartel,parent,false);


        }
       ImageView img=(ImageView)listItemView.findViewById(R.id.img);




switch (position) {


    case 0:


        img.setImageResource(R.mipmap.uno);
        break;
    case 1:
        img.setImageResource(R.mipmap.dos);
        break;
    case 2:
        img.setImageResource(R.mipmap.tres);
        break;
    case 3:
        img.setImageResource(R.mipmap.cuatro);
        break;
    case 4:
        img.setImageResource(R.mipmap.cinco);
        break;
    case 5:
        img.setImageResource(R.mipmap.seis);
        break;
    case 6:
        img.setImageResource(R.mipmap.siete);
        break;
    case 7:
        img.setImageResource(R.mipmap.ocho);
        break;




}





    return listItemView;
}

}

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_width="58dp"
        android:layout_height="58dp"
        android:id="@+id/img" />

    <EditText
        android:layout_width="509dp"
        android:layout_height="61dp"
        android:inputType="textMultiLine"
        android:ems="10"
        android:id="@+id/txt" />
</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="66dp"
    android:weightSum="1">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="121dp"
        android:layout_height="match_parent"
        android:layout_weight="0.55">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="MODE"
            android:id="@+id/textView" />

        <Spinner
            android:layout_width="124dp"
            android:layout_height="wrap_content"
            android:id="@+id/spinner"
            android:entries="@array/mode"/>

    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="119dp"
        android:layout_height="match_parent"
        android:layout_weight="0.36">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SPEED"
            android:id="@+id/textView3" />

        <Spinner
            android:layout_width="118dp"
            android:layout_height="wrap_content"
            android:id="@+id/spinner2"
            android:entries="@array/speed"/>
    </LinearLayout>

</LinearLayout>

    
asked by Sergio Cv 13.04.2016 в 08:55
source

2 answers

1

In a certain way you are using the same view, if it comes within the convertView variable, you are not creating a new listItemView view:

   View listItemView=convertView;
        if (null==convertView){        listItemView=inflater.inflate(R.layout.layoutcartel,parent,false);
        }

only inflates the view always, when the getView () method is executed:

View listItemView =inflater.inflate(R.layout.layoutcartel,parent,false);
    
answered by 13.04.2016 в 13:45
1

Elenasys! that has helped me a lot ... but now I have another problem ... when I fill the first edittext, I scroll down to the last element, and I go back to the first element, it has been restarted and put the empty edittext ....

How can I get it to stay still and not restart the values when it goes out of screen? a greeting! :)

    
answered by 14.04.2016 в 08:40