我有一个自定义ArrayAdapter代表在旋转器上的控制对象,我可以载入我的项目名单,并显示它的选择,但在实际选择发生微调显示什么。
活动代码:
public MetroData metroData;
private Spinner spinner;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
metroData = new MetroData();
spinner = (Spinner) findViewById(R.id.spinner1);
StopArrayAdapter dAdapter = new StopArrayAdapter(this, metroData.Stops);
spinner.setAdapter(dAdapter);
}
StopArrayAdapter:
public class StopArrayAdapter extends ArrayAdapter<MetroStop> {
private List<MetroStop> items;
private Activity activity;
public StopArrayAdapter(Activity activity, List<MetroStop> items) {
super(activity, android.R.layout.simple_list_item_1, items);
this.items = items;
this.activity = activity;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView v = (TextView) super.getView(position, convertView, parent);
if (v == null) {
v = new TextView(activity);
}
v.setTextColor(Color.BLACK);
v.setText(items.get(position).getName());
return v;
}
@Override
public MetroStop getItem(int position) {
return items.get(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = activity.getLayoutInflater();
v = inflater.inflate(R.layout.view_spinner_item, null);
}
TextView lbl = (TextView) v.findViewById(R.id.text1);
lbl.setTextColor(Color.BLACK);
lbl.setText(items.get(position).getName());
return convertView;
}
}
微调视图项模板:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#222"/>
为什么选择的项目视图不工作任何想法? 顺便说一句,我也有同样的结果正常ArrayAdapter试了一下。
更新似乎视图获取生成的,但找上了层次观众的观点是没有得到呈现,测量/规划/绘制= N / A。