0

I have an ArrayList filled with objects of a class, I try to show it on a ListView but I get something weird in return I get the address of the class like project.Class@"alphanumeric" on the first and only line of the ListView Here is the code I've got

private ListView lvWords;

private Word word;

private pWord pword;

private ArrayList<Word> words;

and my onCrete method has this

    this.lvWords=(ListView) this.findViewById(R.id.lvWords);

    this.pword=new oWord(this);

    this.words=new ArrayList<Word>();
    this.words=pword.ReturnArrayList();
    ArrayAdapter<Word> adapter= new ArrayAdapter<Word>(this, android.R.layout.simple_list_item_1, words);
    this.lvWords.setAdapter(adapter);

pword.ReturnArrayList() gets all the words of the database and stores it into a cursor and then each element is converted in a Word object and stored in the array

I'd also like to update it with a button or something

Lucas Araujo
  • 133
  • 1
  • 2
  • 11
  • I'm not sure exactly what you mean by "first and only line", but have a look at [this post](http://stackoverflow.com/questions/27475434/how-to-use-an-arrayadapter-in-android-of-custom-objects) for the "weird" output. If you mean you're only getting one list item, make sure `ReturnArrayList()` is returning what you expect. That is, check the `size()` of the returned `ArrayList`. – Mike M. Aug 20 '16 at 01:00
  • what is the relation of the size of the array and the ListView? It does return an ArrayList of objects of the Word Class – Lucas Araujo Aug 20 '16 at 01:04
  • The `size()` of the `ArrayList` is the number of items in the `ListView`. – Mike M. Aug 20 '16 at 01:06
  • it still does not display the different attributes that a Word object would have – Lucas Araujo Aug 20 '16 at 01:11
  • Oh, that's what you mean. Well, as you read in the linked post, `ArrayAdapter` will display what is returned by an object's `toString()` method, and it will display that in a single `TextView`. If you want all of a `Word`'s attributes in a single `TextView`, you can just alter the `toString()` method to concatenate those attributes as you see fit. If you want a more complicated list item layout - e.g., one with multiple `TextView`s - you will need to implement a custom `Adapter`. – Mike M. Aug 20 '16 at 01:16
  • what I want is each row to be a word and each column an attribute – Lucas Araujo Aug 20 '16 at 01:23
  • Then you will need to implement a custom `Adapter` - or perhaps use a [`SimpleAdapter`](https://developer.android.com/reference/android/widget/SimpleAdapter.html), which I always forget about - with an item layout that uses `LinearLayout`s with weighted `TextView`s. If that's what you're actually asking how to achieve, then I would recommend that you [edit] your question to clarify that. As it is, it just kinda sounds like your main problem was the incorrect `String` output. – Mike M. Aug 20 '16 at 01:39

0 Answers0