I’m pretty new to Android development, and what I’m trying to do is display the contents of an ArrayList in a TextView.
I’ve been attempting to convert the ArrayList into an Array, and then append each item to a StringBuilder. However, the StringBuilder doesn’t appear to allow me to append an Object from the Array. Can anyone tell me why, or in fact provide a better solution?
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
ArrayList<String> temp = new ArrayList<String>();
temp = data.getStringArrayListExtra("intentReturn");
Object obj[] = temp.toArray();
for(int i = 0; i < obj.length; i++){
sBuilder.append((String)obj[i]); //This is the line which crashes the app
if(i < obj.length - 1){
sBuilder.append(", ");
}
}
tvResult.setText(sBuilder.toString());
}
Many thanks in advance.
Apparently I forgot to add
StringBuilder sBuilder = new StringBuilder();– silly newbie! Thanks to Jeffrey for his code clean up too, much appreciated!In order to provide a sufficient answer, here is my new code: