我试图让我的spinneradapter正常工作。我没有得到任何错误,但是 旋转器仍然是空的。我已阅读了多个教程,但它们似乎无法正常工作 很好。我试图以特定颜色转动每一行,这就是我需要适配器的原因。 这是我的代码:
public class spinnerAdapter extends ArrayAdapter<String> implements
SpinnerAdapter {
Context context;
ArrayList<String> dateArray;
public spinnerAdapter(Context context, ArrayList<String>dateArray) {
super(context, R.layout.ruilen2_spinner);
this.context = context;
this.dateArray = dateArray;
}
static class ViewHolder {
public TextView textView;
public TextView textView2;
}
@Override
public View getDropDownView(int position, View view, ViewGroup parent) {
View rowView = view;
final ViewHolder holder;
if (rowView == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
rowView = vi.inflate(R.layout.ruilen2_spinner, null);
holder = new ViewHolder();
holder.textView = (TextView)rowView.findViewById(R.id.spinnerdate);
//holder.textView2 = (TextView)rowView.findViewById(R.id.spinnerworkplace);
rowView.setTag(holder);
}
else{
holder = (ViewHolder) rowView.getTag();
}
holder.textView.setText(dateArray.get(position));
return super.getDropDownView(
position, rowView, parent);
}
}
这是我调用该类的代码段:
s.setAdapter(new spinnerAdapter(getParent(),namen));
最后但并非最不重要的是XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:background="@color/white"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/spinnerdate" android:textColor="@color/black"></TextView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/spinnerworkplace" android:textColor="@color/black"></TextView>
</LinearLayout>
答案 0 :(得分:0)
如果显示但是为空,那么您可能无法正确创建dateArray。您是否检查过以确保namen
中的s.setAdapter(new spinnerAdapter(getParent(),namen));
中有任何内容?