I have created multiple arrays and want to be able to to put them in a list and then have that list, when clicked, display the new list of arrays. Here is what I have come up with so far. I am tring to avoid having to use a switch statement to check every situation.
I starred where I am having the issue. I thought it was pretty elegant idea, but it doesn't work and I am not sure of a work around.
public class Home extends ListActivity {
static public final String TAG = "Home";
ListView list;
ListAdapter lAdapter;
String listString;
String[] currentList;
String[] home;
String[] BY_RACK;
String[] BY_STATION;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
home = getResources().getStringArray(R.array.home);
BY_RACK = getResources().getStringArray(R.array.BY_RACK);
BY_STATION = getResources().getStringArray(R.array.BY_STATION);
currentList = home;
setList(currentList);
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Log.d(TAG, "id;" + id + " position:" + position + " view:" + v);
listString = currentList[position];
listString = listString.replace(" ", "_");
listString = listString.toUpperCase();
Log.d(TAG, "liststrgin:" + listString);
listString.
currentList = listString; ********
}
public void setList(String[] setl) {
list = (ListView) findViewById(android.R.id.list);
lAdapter = new ArrayAdapter(this, R.layout.list_layout, R.id.textView1,setl);
list.setAdapter(lAdapter);
}
currentList = listString;
assigning a String to a String array. I don't think socurrentList = listString;
It is never possible. To avoid switch statement you can useTags
.currentList = listString;
can't work. (String[] = String
!). Why don't you useArrayList
or HashMap? WithHashMap
, you can 'reference' a String[] with a String (HashMap<String, String[]> hm = new HashMap<String, String[]>();
)