Search code examples
androidmotodev-studio

Android ArrayList item in ListView


So I have this list which uses values from an ArrayList (and I can't use String[] because the user must add items to the list, and I can't do .add to the String[]). But now I have problems with onItemClick method. I want to get the text from item selected, and my book says the following should work:

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    dodaj.setText(values[arg2]);

}

But I get the following error: The type of the expression must be an array type but it resolved to ArrayList What should I do to fix it?


Solution

  • is "values" an ArrayList? if so use

    dodaj.setText( (String)values.get( arg2 ) );