android-developers
[Arriba] [Todas las Listas]

[android-developers] ArrayList[0] por ArrayList[n-1] el elemento que es

To: Android Developers <android-developers@xxxxxxxxxxxxxxxx>
Subject: [android-developers] ArrayList[0] por ArrayList[n-1] el elemento que es overwritten por ArrayList[n]
From: Jeff Biss <jeff@xxxxxxxxxxxxx>
Date: Mon, 7 Aug 2017 07:01:52 -0700 (PDT)
Delivery-date: Mon, 07 Aug 2017 10:03:19 -0400
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:date:from:to:message-id:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=ZhcnzuF3/LtXsM0lsB7EzcmWQOuciGA2wXH8t6THSGA=; b=MWV/Me62kwsQ9mJDU2pI7/JEst35EbB6ztRclZgWP+oCT8ANd4JaEfLZ+aAFdcwOHd JFfzNb6TeXaZghtSyksS0MRZJxJEaY4osuIShfgPMs3wQY2l2zc/fb61qdH1xl3S7iLq I/mTl3rvkgeHGv7FXtg7pUW6RQBP68RMZ4LmdLiVsK7cvpLItTzH0yiaKpGKsiToWnH+ +HrLDSCJa0tlBflwVAyNwmOwp9elGQRNEZ+/BlmakvZrD8phkKJZyr0nTlfNOmVb8AbX 6OO58cR6CYby0ArX0mY38XaWdTCnnLaMd6NfjcSQvq4ehwSJE7UYccnpvdQe2PgFJ513 HCxQ==
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marco-inc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:message-id:subject:mime-version:x-original-sender :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=ZhcnzuF3/LtXsM0lsB7EzcmWQOuciGA2wXH8t6THSGA=; b=OqJVrfT8EVTNNL+mXEePmWpfzrgKTpHX6vWpRhTT8PD87h6eq/vCq/GiNkGLjPt63E t+/N1e91FnGHx71t9XAbS5gqId0Hn/iPJfpSROyA/mYhY4dbCmFoFGD0tmTBQaGWJk/2 YNnIGWNjYxxF0FGr57wczi8yrrj1jNCYuT52hFnLq0M6cC66jSpSrOxl1OfygK7wrcdx Rbg2yQse+8Mptx/1q1o9au7KafoQ1Wnu9CpkDtN/Ja2RtW2WtL4Fng8ilx0LPqL1053C rRhC/pWcq+VE7rSHqHCjtVnCEHK7elEn2Di772BmxQHUgUGLDRzLdPtiB+e75wSAYYbm qIgA==
Envelope-to: traductor@xxxxxxxxxxx
List-archive: <https://groups.google.com/group/android-developer>
List-help: <https://groups.google.com/support/>, <mailto:android-developers+help@googlegroups.com>
List-id: <android-developers.googlegroups.com>
List-post: <https://groups.google.com/group/android-developers/post>, <mailto:android-developers@googlegroups.com>
List-subscribe: <https://groups.google.com/group/android-developers/subscribe>, <mailto:android-developers+subscribe@googlegroups.com>
List-unsubscribe: <mailto:googlegroups-manage+364598216046+unsubscribe@googlegroups.com>, <https://groups.google.com/group/android-developers/subscribe>
Mailing-list: list android-developers@xxxxxxxxxxxxxxxx; contact android-developers+owners@xxxxxxxxxxxxxxxx
Reply-to: android-developers@xxxxxxxxxxxxxxxx
Sender: android-developers@xxxxxxxxxxxxxxxx
*Somehow El nombre en el primer *ArrayList posición (ve Línea 6) era 
*overwritten con aquello en el segundo (ve Línea 13). Puede cualquiera ofrece una 
razón cuando a lo que podría ser pasar?

Refiere a *LogCat sección para los números:

- Líneas 2 y 3 espectáculo que el *cursor ha accedido el DB.

- Líneas 4 *thru 9 espectáculo que los nombres son recuperados del DB y pasado 
a *ArrayLists.

- Líneas 10 #por 14 espectáculo el *petNameList contenidos (ve Un) pasado al 
adaptador (ve *B).

- Líneas 15 #por 18 espectáculo *petNameList contenta pasado de *MainActivity 
(ve *C).

- Líneas 22 #por 27 espectáculo que la primera posición del *ArrayList controles 
"*qwerty".

- Líneas 31 #por 36 espectáculo que la segunda posición del *ArrayList controles 
"*qwerty".

Mantendré *experimenting para ver si puedo descubrir lo que pasa y correo él 
si encuentro la razón.

***LogCat:**

    1. !------*MainActivity: Inicios aquí-----!
    2. el DB tiene: 2 filas
    3. *cursor Tiene: 2 filas
    4. El siguiendo tendría que ser igual:  
    5. Nombre de *cursor es: *fert
    6. *petNameList[0] es: *fert
    7. El siguiendo tendría que ser igual:  
    8. Nombre de *cursor es: *qwerty
    9. *petNameList[1] es: *qwerty
    10. *petNameList Es: [com.example.jbiss.petminder.petname@ea7*cc11, 
*com.Ejemplo.*jbiss.*petminder.*PetName@3*c54176]
    11. *petNameList Cuenta es: 2
    12. *petNameList Los Elementos pasados a *mAdapter:  
    13. *petNameList[0] pasado al constructor de adaptador es: *qwerty
    14. *petNameList[1] pasado al constructor de adaptador es: *qwerty

    15. Hecho lo a: *SelectNameAdapter constructor
    16. Los Elementos es: [com.example.jbiss.petminder.petname@ea7*cc11, 
*com.Ejemplo.*jbiss.*petminder.*PetName@3*c54176]
    17. *ArrayList[0] pasado al constructor de adaptador es: *qwerty
    18. *ArrayList[1] pasado al constructor de adaptador es: *qwerty

    19. Hecho lo a: *onCreateViewHolder
    20. Hecho lo a: *ViewHolder
    21. Hecho lo a: *onBindViewHolder
    22. Posición en *ArrayList es: 0
    23. *mItems[0] (*pointer) es: com.example.jbiss.petminder.petname@ea7*cc11
    24. *pNm (*pointer) Es): com.example.jbiss.petminder.petname@ea7*cc11
    25. *pNm (Cadena ) es: *qwerty
    26. NOTA: el elemento tiene que igual *mItems[0]
    27. *onBindViewHolder Pasó: elemento.*getPetName() *qwerty A *ViewHolder
    28. Hecho lo a: *onCreateViewHolder

    29. Hecho lo a: *ViewHolder

    30. Hecho lo a: *onBindViewHolder
    31. Posición en *ArrayList es: 1
    32. *mItems[1] (*pointer) es: *com.Ejemplo.*jbiss.*petminder.*PetName@3*c54176
    33. *pNm (*pointer) Es): *com.Ejemplo.*jbiss.*petminder.*PetName@3*c54176
    34. *pNm (Cadena ) es: *qwerty
    35. NOTA: el elemento tiene que igual *mItems[1]
    36. *onBindViewHolder Pasó: elemento.*getPetName() *qwerty A *ViewHolder


**El código pertinente en *MainActivity:**

        *Log.*d("!------*MainActivity", "Empieza aquí-----!");

        Largo *numItems = *mDbHelper.*getPetCount();
        *Log.*d("el DB tiene", Cadena.*valueOf(*numItems) + " Filas");
        si (*numItems != 0)
            #unknown{^*cursor = *mDbHelper.*getPetNames();
            *numItems = *cursor.*getCount();
            *Log.*d("*cursor Tiene", Cadena.*valueOf(*numItems) + " Filas");
            *cursor.*moveToFirst();

Un)

            puesto que (*int *i = 0; *i < *numItems; *i++)
                #unknown{^*PetName el nombre = nuevo *PetName(*cursor.*getString(NOMBRES_de MASCOTA));
                *Log.*d("El siguiendo tendría que ser igual", " ");
                *Log.*d("Nombre de *cursor es", nombre.*getPetName());
                *petNameList.Añade(nombre);
                //el siguiendo es para *troubleshooting, consigue el 
actualmente añadió *petname
                PN = *petNameList.Consigue(*i);
                *pName = PN.*getPetName();
                *Log.*d("*petNameList[" + *i + "] Es", *pName);
                *cursor.*moveToNext();
            }
        } Más
            //#unknown{^*otherwise, si #ninguno nombres de mascota existen *int él DB, hace las #ninguno mascotas 
el mensaje encontrado visible
            *msgTv.*setText(*R.Cadena.Ninguna_mascota);
            *msgTv.*setVisibility(Vista.VISIBLE);
        }

*B)

        *Log.*d("*petNameList Es", Cadena.*valueOf(*petNameList));
        *num = *petNameList.Medida();
        *Log.*d("*petNameList Cuenta es", Cadena.*valueOf(*num));
        *Log.*d("*petNameList Los Elementos pasados a *mAdapter", " ");
        puesto que(*int *j =0; *j < *num; *j++)
            #nom = *petNameList.Consigue(*j);
            *pName = PN.*getPetName();
            *Log.*d("*petNameList[" + *j + "] Pasado al constructor de adaptador 
es", *pName);
        }
        //*setup el adaptador y aplicarlo al *RecyclerView
        *mAdapter = nuevo *SelectNameAdapter(esto, *petNameList);
        *mRecyclerView.*setAdapter(*mAdapter);


**Código de adaptador:**

    privado *ArrayList<*PetName> *mItems;
    Contexto privado *mContext;

    público *SelectNameAdapter(contexto de Contexto, *ArrayList<*PetName> elementos)
        #unknown{^*Log.*d("Hecho lo a ," "*SelectNameAdapter constructor");
        *Log.*d("Los Elementos es", Cadena.*valueOf(Elementos));
        *PetName PN;
        nombre de Cadena;

*C)

        *int *num = elementos.Medida();
        puesto que(*int *j =0; *j < *num; *j++)
            #nom_de_nom = de PN.Consigue(*j);
            PN = de nombre.*getPetName();
            *Log.*d("*ArrayList[" + *j + "] Pasado al constructor de adaptador 
es", nombre);
        }
        esto.*mContext = Contexto;
        esto.*mItems = Elementos;
    }

    @*Override
    público *SelectNameAdapter.*ViewHolder *onCreateViewHolder(*ViewGroup 
Padre, *int *i)
        #unknown{^*Log.*d("Hecho lo a ," "*onCreateViewHolder");
        *LayoutInflater *inflater = *LayoutInflater.De(*mContext);
        Vista *itemView = *inflater.*inflate(*R.*layout.Mascota_*info, padre, falso);
        *ViewHolder *viewHolder = nuevo *ViewHolder(*itemView);
        regreso *viewHolder;
    }

    @*Override
    público *void *onBindViewHolder(*SelectNameAdapter.*ViewHolder Titular, *int 
posición)
        #unknown{^*Log.*d("Hecho lo a ," "*onBindViewHolder");
        *Log.*d("Posición en *ArrayList es", Cadena.*valueOf(Posición));
        *Log.*d("*mItems[" + Posición + "] (*pointer) es", 
Cadena.*valueOf(*mItems.Consigue(posición)));
        *PetName *pNm = *mItems.Consigue(posición);
        *Log.*d("*pNm (*pointer) Es)", Cadena.*valueOf(*pNm));
        Cadena *n = *pNm.*getPetName();
        *Log.*d("*pNm (Cadena ) es", *n);
        *Log.*d("NOTA", "el elemento tiene que igual *mItems[" + posición + "]");
        titular.*tvName.*setText(*pNm.*getPetName());
        *Log.*d("*onBindViewHolder Pasado ", "elemento.*getPetName() " + 
*pNm.*getPetName() + " A *ViewHolder");
    }

    @*Override
    público *int *getItemCount()
        #nom *mItems.Medida();
    }

    público *static clase *ViewHolder extiende *RecyclerView.*ViewHolder

        #Nom *TextView *tvName;
        público *ViewHolder(Vista *itemView)
            #unknown{^*super(*itemView);
            *Log.*d("Hecho lo a ," "*ViewHolder");
            *tvName = (*TextView) *itemView.*findViewById(*R.*id.*petname);
        }
    }
    }

-- 
Recibiste este mensaje porque eres *subscribed al *Google Grupos "*Android *Developers" grupo.
A *unsubscribe de este grupo y la parón que recibe *emails de él, enviar un *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx.
A correo a este grupo, envía *email a *android-developers@xxxxxxxxxxxxxxxx.
Visita este grupo en *https://grupos.*google.*com/Grupo/*android-*developers.
Para ver esta discusión en la visita de web *https://grupos.*google.*com/*d/*msgid/*android-*developers/89*eaa894-*e324-487*c-*adae-*f094#uno83*e26*c4%40*googlegroups.*com.
Para más opciones, visita *https://grupos.*google.*com/*d/*optout.
Somehow the name in the first ArrayList position (see Line 6) was 
overwritten with that in the second (see Line 13). Can anyone offer a 
reason as to what might be happening?

Refer to LogCat section for the numbers:

- Lines 2 and 3 show that the cursor has accessed the DB.

- Lines 4 thru 9 show that the names are retrieved from the DB and passed 
to ArrayLists.

- Lines 10 through 14 show the petNameList contents (see A) passed to the 
adapter (see B).

- Lines 15 through 18 show petNameList contents passed from MainActivity 
(see C).

- Lines 22 through 27 show that the first position of the ArrayList holds 
"qwerty".

- Lines 31 through 36 show that the second position of the ArrayList holds 
"qwerty".

I will keep experimenting to see if I can find out what happens and post it 
if I find the reason.

**LogCat:**

    1. !------MainActivity: Starts here-----!
    2. DB has: 2 rows
    3. cursor has: 2 rows
    4. The following should be the same:  
    5. name from cursor is: fert
    6. petNameList[0] is: fert
    7. The following should be the same:  
    8. name from cursor is: qwerty
    9. petNameList[1] is: qwerty
    10. petNameList is: [com.example.jbiss.petminder.PetName@ea7cc11, 
com.example.jbiss.petminder.PetName@3c54176]
    11. petNameList count is: 2
    12. petNameList elements passed to mAdapter:  
    13. petNameList[0] passed to the adapter constructor is: qwerty
    14. petNameList[1] passed to the adapter constructor is: qwerty

    15. made it to: SelectNameAdapter constructor
    16. items is: [com.example.jbiss.petminder.PetName@ea7cc11, 
com.example.jbiss.petminder.PetName@3c54176]
    17. ArrayList[0] passed to the adapter constructor is: qwerty
    18. ArrayList[1] passed to the adapter constructor is: qwerty

    19. made it to: onCreateViewHolder
    20. made it to: ViewHolder
    21. made it to: onBindViewHolder
    22. position in ArrayList is: 0
    23. mItems[0] (pointer) is: com.example.jbiss.petminder.PetName@ea7cc11
    24. pNm (pointer) is): com.example.jbiss.petminder.PetName@ea7cc11
    25. pNm (String ) is: qwerty
    26. NOTE: item should equal mItems[0]
    27. onBindViewHolder passed: item.getPetName() qwerty to ViewHolder
    28. made it to: onCreateViewHolder

    29. made it to: ViewHolder

    30. made it to: onBindViewHolder
    31. position in ArrayList is: 1
    32. mItems[1] (pointer) is: com.example.jbiss.petminder.PetName@3c54176
    33. pNm (pointer) is): com.example.jbiss.petminder.PetName@3c54176
    34. pNm (String ) is: qwerty
    35. NOTE: item should equal mItems[1]
    36. onBindViewHolder passed: item.getPetName() qwerty to ViewHolder


**The relevant code in MainActivity:**

        Log.d("!------MainActivity", "Starts here-----!");

        long numItems = mDbHelper.getPetCount();
        Log.d("DB has", String.valueOf(numItems) + " rows");
        if (numItems != 0) {
            cursor = mDbHelper.getPetNames();
            numItems = cursor.getCount();
            Log.d("cursor has", String.valueOf(numItems) + " rows");
            cursor.moveToFirst();

A)

            for (int i = 0; i < numItems; i++) {
                PetName name = new PetName(cursor.getString(PET_NAMES));
                Log.d("The following should be the same", " ");
                Log.d("name from cursor is", name.getPetName());
                petNameList.add(name);
                //the following is for troubleshooting, it gets the 
currently added petname
                PN = petNameList.get(i);
                pName = PN.getPetName();
                Log.d("petNameList[" + i + "] is", pName);
                cursor.moveToNext();
            }
        } else{
            //otherwise, if no pet names exist int he DB, make the no pets 
found message visible
            msgTv.setText(R.string.no_pets);
            msgTv.setVisibility(View.VISIBLE);
        }

B)

        Log.d("petNameList is", String.valueOf(petNameList));
        num = petNameList.size();
        Log.d("petNameList count is", String.valueOf(num));
        Log.d("petNameList elements passed to mAdapter", " ");
        for(int j =0; j < num; j++){
            PN = petNameList.get(j);
            pName = PN.getPetName();
            Log.d("petNameList[" + j + "] passed to the adapter constructor 
is", pName);
        }
        //setup the adapter and apply it to the RecyclerView
        mAdapter = new SelectNameAdapter(this, petNameList);
        mRecyclerView.setAdapter(mAdapter);


**Adapter code:**

    private ArrayList<PetName> mItems;
    private Context mContext;

    public SelectNameAdapter(Context context, ArrayList<PetName> items) {
        Log.d("made it to", "SelectNameAdapter constructor");
        Log.d("items is", String.valueOf(items));
        PetName PN;
        String name;

C)

        int num = items.size();
        for(int j =0; j < num; j++){
            PN = items.get(j);
            name = PN.getPetName();
            Log.d("ArrayList[" + j + "] passed to the adapter constructor 
is", name);
        }
        this.mContext = context;
        this.mItems = items;
    }

    @Override
    public SelectNameAdapter.ViewHolder onCreateViewHolder(ViewGroup 
parent, int i) {
        Log.d("made it to", "onCreateViewHolder");
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View itemView = inflater.inflate(R.layout.pet_info, parent, false);
        ViewHolder viewHolder = new ViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(SelectNameAdapter.ViewHolder holder, int 
position) {
        Log.d("made it to", "onBindViewHolder");
        Log.d("position in ArrayList is", String.valueOf(position));
        Log.d("mItems[" + position + "] (pointer) is", 
String.valueOf(mItems.get(position)));
        PetName pNm = mItems.get(position);
        Log.d("pNm (pointer) is)", String.valueOf(pNm));
        String n = pNm.getPetName();
        Log.d("pNm (String ) is", n);
        Log.d("NOTE", "item should equal mItems[" + position + "]");
        holder.tvName.setText(pNm.getPetName());
        Log.d("onBindViewHolder passed ", "item.getPetName() " + 
pNm.getPetName() + " to ViewHolder");
    }

    @Override
    public int getItemCount() {
        return mItems.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        public TextView tvName;
        public ViewHolder(View itemView) {
            super(itemView);
            Log.d("made it to", "ViewHolder");
            tvName = (TextView) itemView.findViewById(R.id.petname);
        }
    }
    }

-- 
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to android-developers@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/89eaa894-e324-487c-adae-f094a83e26c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<Anterior por Tema] Tema Actual [Siguiente por Tema>
  • [android-developers] ArrayList[0] por ArrayList[n-1] el elemento que es overwritten por ArrayList[n], Jeff Biss <=