0

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);


}
6
  • When you say it doesn't work, what happens? Commented Jul 25, 2013 at 3:39
  • I thought it was pretty elegant idea, currentList = listString; assigning a String to a String array. I don't think so Commented Jul 25, 2013 at 3:44
  • currentList = listString; It is never possible. To avoid switch statement you can use Tags. Commented Jul 25, 2013 at 3:44
  • I am sorry I am pretty new to programing, what do you mean use Tags? Commented Jul 25, 2013 at 3:55
  • currentList = listString; can't work. (String[] = String !). Why don't you use ArrayList or HashMap? With HashMap, you can 'reference' a String[] with a String (HashMap<String, String[]> hm = new HashMap<String, String[]>();) Commented Jul 25, 2013 at 7:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.