我创建了两个微调器来显示应用程序中的数据。在第一个微调器中,列表的第一个项目始终直接显示,但在第二个微调器中,不显示任何内容,即使我单击下拉视图中的项目。有人能解释这种行为吗?
以下是两个微调器初始化的代码:
projects = new Spinner(lexs);
projectAdapter = new ProjectAdapter();
projects.setAdapter(projectAdapter);
projects.setMinimumWidth(250);
projects.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
updateSpinners(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// do nothing
}
});
projectsList = new Spinner(lexs);
projectsList.setMinimumWidth(250);
listAdapter = new ListAdapter();
projectsList.setAdapter(listAdapter);
projectsListLayer.addView(projectsList);
自旋体项目是第一个正确工作的自旋体。ProjectsList是第二个无法正常工作的微调器。下面是适配器的两个实现:
private class ProjectAdapter implements SpinnerAdapter {
@Override
public View getDropDownView(int position, View arg1, ViewGroup arg2) {
TextView text = new TextView(lexs);
text.setText(allProjects.get(position).getName());
return text;
}
@Override
public int getCount() {
return allProjects.size();
}
@Override
public Object getItem(int position) {
return allProjects.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View arg1, ViewGroup arg2) {
TextView text = new TextView(lexs);
text.setText(allProjects.get(position).getName());
return text;
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isEmpty() {
if (allProjects.size() == 0) {
return true;
} else {
return false;
}
}
@Override
public void registerDataSetObserver(DataSetObserver arg0) {
// TODO Auto-generated method stub
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
// TODO Auto-generated method stub
}
}
private class ListAdapter implements SpinnerAdapter {
@Override
public View getDropDownView(int position, View view, ViewGroup parent) {
TextView text = new TextView(lexs);
text.setText(allLists.get(position).getName());
return text;
}
@Override
public int getCount() {
return allLists.size();
}
@Override
public Object getItem(int position) {
return allLists.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView text = new TextView(lexs);
text.setText(allLists.get(position).getName());
return text;
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEmpty() {
if (allLists.size() == 0) {
return true;
} else {
return false;
}
}
@Override
public void registerDataSetObserver(DataSetObserver observer) {
// TODO Auto-generated method stub
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
// TODO Auto-generated method stub
}
}
在这里,我附上了问题的图片:
http://www.freeimagehosting.net/image.php?7684c157b8.png