我创建了多个数组,并希望能够将它们放在一个列表中,然后让该列表在单击时显示新的数组列表。到目前为止,这是我想出的。我试图避免使用 switch 语句来检查每种情况。
我在我遇到问题的地方加注了星标。我认为这是一个非常优雅的想法,但它不起作用,我不确定是否可以解决。
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);
}