ListView muestra solo texto en lugar de Vistas

I've been searching and testing the whole day, but I didn't find any solution for this problem. I've got a ListView and I want to show some Views in that. But everytime I add a view, it only shows me the class or the id of the listItems instead of the Views themselves. Like:

android.widget.Button{40f090e0VFED.. C. ..........l. 0,0-0,0}

What am I doing wrong!? Do I have to set a certain tag!? This is how my Listview is implemented in the xml-file

    android:splitMotionEvents="true" >

and this ist the java-code in the activity:

Button[] test = new Button[3];
test[0] = new Button((Activity) _mycontext);
test[1] = new Button((Activity) _mycontext);
test[2] = new Button((Activity) _mycontext);
test[0].setText("Test-Button 1");
test[1].setText("Test-Button 2");
test[2].setText("Test-Button 3");
_dt_columns.setAdapter(new ArrayAdapter<View>((Activity) _mycontext, android.R.layout.simple_list_item_1, test));

I also did it all the way with "extends ListActivity" and the Inflater, and it all shows up, but there's always just that text, not the views themselves.

preguntado el 26 de mayo de 13 a las 01:05

Wouldn't you need a custom view to inflate if you want to only display buttons in your list? -

What is "android.widget.Button{40f090e0VFED.. C. ..........l. 0,0-0,0}" -

Sorry, I don't even understand what you are trying to do. What do you mean by "ListView with some views"? -

I want to create a set of Views (2 TextViews and an ImageButton) in each row of the ListView! But first I want to get even one simple Button THAT IS NOT JUST A STRING into that ListView! But when I do that, only that strange "android.widget.Button{40..." text in the lisview ist being shown, but not the button itself as it should. -

I have even tried to import and use this code from this page: but I get two errors, after doing all the imports. So that code doesn't really work! -

1 Respuestas

ArrayAdapter populates ListView only with one TextView, each item may have some complex layout but the only difference between them will be a TextView value.

You are passing View elements as list items and adapter call toString method on them to populate this TextView, that is where You get this "strange" values from.

Create Your own xml layout resource for single list item with desired structure instead of using android.R.layout.simple_list_item_1. And create Your asdapter like this

ArrayAdapter<YourObject> adapter = new ArrayAdapter<YourObject>(this, R.layout.listitem,, YourObject[])

where YourObject is a class You created to hold data for single item and toString method return value You wish to display in list.

respondido 11 nov., 13:23

ok! Thanks! That should be it! I'll try it and give a feedback later! :-) - HA

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