Grant Espanet Grant Espanet - 8 months ago 48
Android Question

Can R.string. be used in a ArrayList?

When I build/run my app, "2131165360" appears in the list view position instead of "LegKick Block 1". Why does this happen when i enter this code?


I could solve my problem by doing this but I'd rather grab the value of the string rather than hard-coding it:

arrayList.add("LegKick Block 1");

Is there an approach to put a value of a string in a array list?


Use list.add(getString(R.string.legkick_block1));


returns a integer value to resource, you need to use getResource().getString(R.string.any_string) Or simply getString(R.string.any_string) which returns the string object mapped to the integer resource which you can add in list