我已经创建了多个数组,并且希望能够将它们放入列表中然后拥有该列表,当单击时,显示新的数组列表。这是我到目前为止所提出的。我想避免使用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);
}