Wednesday, 2 October 2013

How to map two String[] to each other

How to map two String[] to each other

I'm developing an Android app. I'm mapping two arrays to each other with a
HashMap. I change these arrays into String[]'s, and map them together. It
should return values, but it returns null. I'm not sure where I'm going
wrong. I've searched online, but I haven't found anything useful. My code
is below:
Part of StationList.java
Spinner2.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String selectedValue =
arg0.getItemAtPosition(arg2).toString();
String[] Yellow_ID =
getResources().getStringArray(R.array.Yellow_ID);
String[] Yellow_Li =
getResources().getStringArray(R.array.Yellow_Line);
Map<String[], String[]> myMap = new HashMap<String[],
String[]>();
myMap.put(Yellow_Li, Yellow_ID);
String[] value = myMap.get(selectedValue);
tv12.setText(String.valueOf (value));
}
Value returns null in the TextView. I think this is due to the values not
mapping to each other. I would appreciate any help you could give me.

No comments:

Post a Comment