The same text displaying over and over in ListView
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
The textView that I'm currently using in my ListView is being displayed over and over, without changing it's information, but I'm not able to see why, can I get a litte help? Code:
Main code named Principal.java:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
public class Principal extends AppCompatActivity {
ListView lista;
Stringdatos = {
{"Mediciones del día"},
{" "},
{"Promedios del día"},
};
int datosImg = {R.drawable.celeste, R.drawable.rojo, R.drawable.verde};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
lista = (ListView) findViewById(R.id.lvLista);
lista.setAdapter(new Adaptador(this, datos, datosImg));
}
}
My adapter:
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class Adaptador extends BaseAdapter {
private static LayoutInflater inflater = null;
Context contexto;
String datos;
int datosImg;
public Adaptador (Context context, String datos,int imagenes)
{
this.contexto = context;
this.datos = datos;
this.datosImg = imagenes;
inflater =
(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int i, View convertView, ViewGroup parent) {
final View vista = inflater.inflate(R.layout.elemento_lista, null);
TextView titulo = (TextView) vista.findViewById(R.id.textView);
ImageView imagen = (ImageView) vista.findViewById(R.id.imageView);
titulo.setText(datos[0][0]);
imagen.setImageResource(datosImg[i]);
/*
imagen.setTag(i);
*/
/*
imagen.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent visorImagen = new Intent(contexto, VisorImagen.class);
visorImagen.putExtra("IMG", datosImg[(Integer)v.getTag()]);
contexto.startActivity(visorImagen);
}
});
*/
return vista;
}
@Override
public int getCount() {
return datosImg.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
}
I have been looking for the solution for a really long time, but I haven't found anything online.
android android-listview
add a comment |
The textView that I'm currently using in my ListView is being displayed over and over, without changing it's information, but I'm not able to see why, can I get a litte help? Code:
Main code named Principal.java:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
public class Principal extends AppCompatActivity {
ListView lista;
Stringdatos = {
{"Mediciones del día"},
{" "},
{"Promedios del día"},
};
int datosImg = {R.drawable.celeste, R.drawable.rojo, R.drawable.verde};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
lista = (ListView) findViewById(R.id.lvLista);
lista.setAdapter(new Adaptador(this, datos, datosImg));
}
}
My adapter:
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class Adaptador extends BaseAdapter {
private static LayoutInflater inflater = null;
Context contexto;
String datos;
int datosImg;
public Adaptador (Context context, String datos,int imagenes)
{
this.contexto = context;
this.datos = datos;
this.datosImg = imagenes;
inflater =
(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int i, View convertView, ViewGroup parent) {
final View vista = inflater.inflate(R.layout.elemento_lista, null);
TextView titulo = (TextView) vista.findViewById(R.id.textView);
ImageView imagen = (ImageView) vista.findViewById(R.id.imageView);
titulo.setText(datos[0][0]);
imagen.setImageResource(datosImg[i]);
/*
imagen.setTag(i);
*/
/*
imagen.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent visorImagen = new Intent(contexto, VisorImagen.class);
visorImagen.putExtra("IMG", datosImg[(Integer)v.getTag()]);
contexto.startActivity(visorImagen);
}
});
*/
return vista;
}
@Override
public int getCount() {
return datosImg.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
}
I have been looking for the solution for a really long time, but I haven't found anything online.
android android-listview
1
Hi there! I recommend you try debugging the code yourself first, the community won't do it for you. Also it is a skill all good programmers require so you might as well start learning/practicing now! Ask google for debugging tips, there's loads of tutorials out there :)
– Burkely91
Nov 23 '18 at 14:23
Thanks! I found the solution doing that! :)
– Draft32
Nov 23 '18 at 14:32
2
Awesome!! If you found the answer you can answer your own question so others with the same problem can see the solution :)
– Burkely91
Nov 23 '18 at 14:35
add a comment |
The textView that I'm currently using in my ListView is being displayed over and over, without changing it's information, but I'm not able to see why, can I get a litte help? Code:
Main code named Principal.java:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
public class Principal extends AppCompatActivity {
ListView lista;
Stringdatos = {
{"Mediciones del día"},
{" "},
{"Promedios del día"},
};
int datosImg = {R.drawable.celeste, R.drawable.rojo, R.drawable.verde};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
lista = (ListView) findViewById(R.id.lvLista);
lista.setAdapter(new Adaptador(this, datos, datosImg));
}
}
My adapter:
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class Adaptador extends BaseAdapter {
private static LayoutInflater inflater = null;
Context contexto;
String datos;
int datosImg;
public Adaptador (Context context, String datos,int imagenes)
{
this.contexto = context;
this.datos = datos;
this.datosImg = imagenes;
inflater =
(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int i, View convertView, ViewGroup parent) {
final View vista = inflater.inflate(R.layout.elemento_lista, null);
TextView titulo = (TextView) vista.findViewById(R.id.textView);
ImageView imagen = (ImageView) vista.findViewById(R.id.imageView);
titulo.setText(datos[0][0]);
imagen.setImageResource(datosImg[i]);
/*
imagen.setTag(i);
*/
/*
imagen.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent visorImagen = new Intent(contexto, VisorImagen.class);
visorImagen.putExtra("IMG", datosImg[(Integer)v.getTag()]);
contexto.startActivity(visorImagen);
}
});
*/
return vista;
}
@Override
public int getCount() {
return datosImg.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
}
I have been looking for the solution for a really long time, but I haven't found anything online.
android android-listview
The textView that I'm currently using in my ListView is being displayed over and over, without changing it's information, but I'm not able to see why, can I get a litte help? Code:
Main code named Principal.java:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
public class Principal extends AppCompatActivity {
ListView lista;
Stringdatos = {
{"Mediciones del día"},
{" "},
{"Promedios del día"},
};
int datosImg = {R.drawable.celeste, R.drawable.rojo, R.drawable.verde};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
lista = (ListView) findViewById(R.id.lvLista);
lista.setAdapter(new Adaptador(this, datos, datosImg));
}
}
My adapter:
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class Adaptador extends BaseAdapter {
private static LayoutInflater inflater = null;
Context contexto;
String datos;
int datosImg;
public Adaptador (Context context, String datos,int imagenes)
{
this.contexto = context;
this.datos = datos;
this.datosImg = imagenes;
inflater =
(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int i, View convertView, ViewGroup parent) {
final View vista = inflater.inflate(R.layout.elemento_lista, null);
TextView titulo = (TextView) vista.findViewById(R.id.textView);
ImageView imagen = (ImageView) vista.findViewById(R.id.imageView);
titulo.setText(datos[0][0]);
imagen.setImageResource(datosImg[i]);
/*
imagen.setTag(i);
*/
/*
imagen.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent visorImagen = new Intent(contexto, VisorImagen.class);
visorImagen.putExtra("IMG", datosImg[(Integer)v.getTag()]);
contexto.startActivity(visorImagen);
}
});
*/
return vista;
}
@Override
public int getCount() {
return datosImg.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
}
I have been looking for the solution for a really long time, but I haven't found anything online.
android android-listview
android android-listview
edited Nov 23 '18 at 19:22
Zoe
13.5k85486
13.5k85486
asked Nov 23 '18 at 14:08
Draft32Draft32
12
12
1
Hi there! I recommend you try debugging the code yourself first, the community won't do it for you. Also it is a skill all good programmers require so you might as well start learning/practicing now! Ask google for debugging tips, there's loads of tutorials out there :)
– Burkely91
Nov 23 '18 at 14:23
Thanks! I found the solution doing that! :)
– Draft32
Nov 23 '18 at 14:32
2
Awesome!! If you found the answer you can answer your own question so others with the same problem can see the solution :)
– Burkely91
Nov 23 '18 at 14:35
add a comment |
1
Hi there! I recommend you try debugging the code yourself first, the community won't do it for you. Also it is a skill all good programmers require so you might as well start learning/practicing now! Ask google for debugging tips, there's loads of tutorials out there :)
– Burkely91
Nov 23 '18 at 14:23
Thanks! I found the solution doing that! :)
– Draft32
Nov 23 '18 at 14:32
2
Awesome!! If you found the answer you can answer your own question so others with the same problem can see the solution :)
– Burkely91
Nov 23 '18 at 14:35
1
1
Hi there! I recommend you try debugging the code yourself first, the community won't do it for you. Also it is a skill all good programmers require so you might as well start learning/practicing now! Ask google for debugging tips, there's loads of tutorials out there :)
– Burkely91
Nov 23 '18 at 14:23
Hi there! I recommend you try debugging the code yourself first, the community won't do it for you. Also it is a skill all good programmers require so you might as well start learning/practicing now! Ask google for debugging tips, there's loads of tutorials out there :)
– Burkely91
Nov 23 '18 at 14:23
Thanks! I found the solution doing that! :)
– Draft32
Nov 23 '18 at 14:32
Thanks! I found the solution doing that! :)
– Draft32
Nov 23 '18 at 14:32
2
2
Awesome!! If you found the answer you can answer your own question so others with the same problem can see the solution :)
– Burkely91
Nov 23 '18 at 14:35
Awesome!! If you found the answer you can answer your own question so others with the same problem can see the solution :)
– Burkely91
Nov 23 '18 at 14:35
add a comment |
3 Answers
3
active
oldest
votes
You could make the datos
an array list like: ArrayList<String>
and add elements with yourList.add()
. Then in the adapter set the text to the TextView
with titulo.setText(yourList.get(i)
.
Hope it helps!
add a comment |
I found the solution!, intead of
titulo.setText(datos[i][0]);
imagen.setImageResource(datosImg[i]);
I wrote:
titulo.setText(datos[0][0]);
imagen.setImageResource(datosImg[i]);
This means that it only shows 1 text, but the other one displays one text, and then goes to the next one. thanks for helping!
add a comment |
you are supposed to give position here, evrytime you set [0][0] will return the same value eveytime, do somthing like this.
public View getView(int i, View convertView, ViewGroup parent) {
final View vista = inflater.inflate(R.layout.elemento_lista, null);
TextView titulo = (TextView) vista.findViewById(R.id.textView);
ImageView imagen = (ImageView) vista.findViewById(R.id.imageView);
titulo.setText(datos[i][i]);
imagen.setImageResource(datosImg[i]);
/*
imagen.setTag(i);
*/
/*
imagen.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent visorImagen = new Intent(contexto, VisorImagen.class);
visorImagen.putExtra("IMG", datosImg[(Integer)v.getTag()]);
contexto.startActivity(visorImagen);
}
});
*/
return vista;
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448201%2fthe-same-text-displaying-over-and-over-in-listview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could make the datos
an array list like: ArrayList<String>
and add elements with yourList.add()
. Then in the adapter set the text to the TextView
with titulo.setText(yourList.get(i)
.
Hope it helps!
add a comment |
You could make the datos
an array list like: ArrayList<String>
and add elements with yourList.add()
. Then in the adapter set the text to the TextView
with titulo.setText(yourList.get(i)
.
Hope it helps!
add a comment |
You could make the datos
an array list like: ArrayList<String>
and add elements with yourList.add()
. Then in the adapter set the text to the TextView
with titulo.setText(yourList.get(i)
.
Hope it helps!
You could make the datos
an array list like: ArrayList<String>
and add elements with yourList.add()
. Then in the adapter set the text to the TextView
with titulo.setText(yourList.get(i)
.
Hope it helps!
answered Nov 23 '18 at 14:14
Alexandru MihailaAlexandru Mihaila
862
862
add a comment |
add a comment |
I found the solution!, intead of
titulo.setText(datos[i][0]);
imagen.setImageResource(datosImg[i]);
I wrote:
titulo.setText(datos[0][0]);
imagen.setImageResource(datosImg[i]);
This means that it only shows 1 text, but the other one displays one text, and then goes to the next one. thanks for helping!
add a comment |
I found the solution!, intead of
titulo.setText(datos[i][0]);
imagen.setImageResource(datosImg[i]);
I wrote:
titulo.setText(datos[0][0]);
imagen.setImageResource(datosImg[i]);
This means that it only shows 1 text, but the other one displays one text, and then goes to the next one. thanks for helping!
add a comment |
I found the solution!, intead of
titulo.setText(datos[i][0]);
imagen.setImageResource(datosImg[i]);
I wrote:
titulo.setText(datos[0][0]);
imagen.setImageResource(datosImg[i]);
This means that it only shows 1 text, but the other one displays one text, and then goes to the next one. thanks for helping!
I found the solution!, intead of
titulo.setText(datos[i][0]);
imagen.setImageResource(datosImg[i]);
I wrote:
titulo.setText(datos[0][0]);
imagen.setImageResource(datosImg[i]);
This means that it only shows 1 text, but the other one displays one text, and then goes to the next one. thanks for helping!
answered Nov 23 '18 at 14:35
Draft32Draft32
12
12
add a comment |
add a comment |
you are supposed to give position here, evrytime you set [0][0] will return the same value eveytime, do somthing like this.
public View getView(int i, View convertView, ViewGroup parent) {
final View vista = inflater.inflate(R.layout.elemento_lista, null);
TextView titulo = (TextView) vista.findViewById(R.id.textView);
ImageView imagen = (ImageView) vista.findViewById(R.id.imageView);
titulo.setText(datos[i][i]);
imagen.setImageResource(datosImg[i]);
/*
imagen.setTag(i);
*/
/*
imagen.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent visorImagen = new Intent(contexto, VisorImagen.class);
visorImagen.putExtra("IMG", datosImg[(Integer)v.getTag()]);
contexto.startActivity(visorImagen);
}
});
*/
return vista;
}
add a comment |
you are supposed to give position here, evrytime you set [0][0] will return the same value eveytime, do somthing like this.
public View getView(int i, View convertView, ViewGroup parent) {
final View vista = inflater.inflate(R.layout.elemento_lista, null);
TextView titulo = (TextView) vista.findViewById(R.id.textView);
ImageView imagen = (ImageView) vista.findViewById(R.id.imageView);
titulo.setText(datos[i][i]);
imagen.setImageResource(datosImg[i]);
/*
imagen.setTag(i);
*/
/*
imagen.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent visorImagen = new Intent(contexto, VisorImagen.class);
visorImagen.putExtra("IMG", datosImg[(Integer)v.getTag()]);
contexto.startActivity(visorImagen);
}
});
*/
return vista;
}
add a comment |
you are supposed to give position here, evrytime you set [0][0] will return the same value eveytime, do somthing like this.
public View getView(int i, View convertView, ViewGroup parent) {
final View vista = inflater.inflate(R.layout.elemento_lista, null);
TextView titulo = (TextView) vista.findViewById(R.id.textView);
ImageView imagen = (ImageView) vista.findViewById(R.id.imageView);
titulo.setText(datos[i][i]);
imagen.setImageResource(datosImg[i]);
/*
imagen.setTag(i);
*/
/*
imagen.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent visorImagen = new Intent(contexto, VisorImagen.class);
visorImagen.putExtra("IMG", datosImg[(Integer)v.getTag()]);
contexto.startActivity(visorImagen);
}
});
*/
return vista;
}
you are supposed to give position here, evrytime you set [0][0] will return the same value eveytime, do somthing like this.
public View getView(int i, View convertView, ViewGroup parent) {
final View vista = inflater.inflate(R.layout.elemento_lista, null);
TextView titulo = (TextView) vista.findViewById(R.id.textView);
ImageView imagen = (ImageView) vista.findViewById(R.id.imageView);
titulo.setText(datos[i][i]);
imagen.setImageResource(datosImg[i]);
/*
imagen.setTag(i);
*/
/*
imagen.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent visorImagen = new Intent(contexto, VisorImagen.class);
visorImagen.putExtra("IMG", datosImg[(Integer)v.getTag()]);
contexto.startActivity(visorImagen);
}
});
*/
return vista;
}
edited Nov 23 '18 at 19:22
Zoe
13.5k85486
13.5k85486
answered Nov 23 '18 at 14:12
Taha wakeelTaha wakeel
896
896
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448201%2fthe-same-text-displaying-over-and-over-in-listview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Hi there! I recommend you try debugging the code yourself first, the community won't do it for you. Also it is a skill all good programmers require so you might as well start learning/practicing now! Ask google for debugging tips, there's loads of tutorials out there :)
– Burkely91
Nov 23 '18 at 14:23
Thanks! I found the solution doing that! :)
– Draft32
Nov 23 '18 at 14:32
2
Awesome!! If you found the answer you can answer your own question so others with the same problem can see the solution :)
– Burkely91
Nov 23 '18 at 14:35