Passing variable string to create arrays (Android)
Posted
by dweebsonduty
on Stack Overflow
See other posts from Stack Overflow
or by dweebsonduty
Published on 2010-05-24T03:46:27Z
Indexed on
2010/05/24
3:51 UTC
Read the original article
Hit count: 218
Hello all,
I am a newb to Android and Java and want to write a funtion that will display a list based on a varable that I pass to the function.
The function is below and the code below creates an array out of a string called type, but what I want to do is pass it a variable string and have it build a list based on that string.
So if I wanted the type list I would say list_it("type")
But if I try something like getResources().getStringArray(R.array.thelist);
it doesn't work.
Can someone point me in the right direction?
public void list_it(String thelist){
String[] types = getResources().getStringArray(R.array.type);
ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(this, R.layout.list_item1, types);
setListAdapter(mAdapter);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
}
© Stack Overflow or respective owner