我尝试为微调器创建列表对话框,但我有错误“ArrayAdapter需要资源ID为TextView”我为它创建了我的custum适配器
public class OrderTypeAdapter extends ArrayAdapter<String> {
private final Context context;
private final List<String> values;
private class ResourseHolder{
protected TextView text;
}
public OrderTypeAdapter(Context context, List<String> values) {
super(context, R.layout.item_list_dialog,values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.item_list_dialog,parent,false);
ResourseHolder holder = new ResourseHolder();
holder.text = (TextView) rowView.findViewById(R.id.ild_main_text_view);
rowView.setTag(holder);
} else {
rowView = convertView;
}
ResourseHolder holder = (ResourseHolder) rowView.getTag();
holder.text.setText(values.get(position));
return rowView;
}
}
项目的xml代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/ild_main_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
我通过标准方式将Addapter设置为微调器
OrderTypeAdapter adapter =new OrderTypeAdapter(getApplicationContext(),
Convert.toList(searchParam.getOrderTypes()));
orderTypeSpinner.setAdapter(adapter);
当我点击旋转器显示对话框时,我的应用程序崩溃,但是当我尝试使用ArrayAdapter时,一切正常。这里有什么问题 ?
答案 0 :(得分:1)
您正在寻找
rowView.findViewById(R.id.ild_main_text_view);
但在你的布局中你有
@+id/item_text_view
所以你应该相应地改变它:
rowView.findViewById(R.id.item_text_view);
答案 1 :(得分:0)
在你的其他情况下做
holder = (ResourseHolder) rowview.getTag()
并在开始时使用转换视图初始化rowview
答案 2 :(得分:0)
我决定使用扩展BaseAdapter insteed ArrayAdapter的问题:)
答案 3 :(得分:0)
您没有在自定义的Arrayadapter.spinners中定义getDropDownView,需要在数组适配器中使用getdropdown方法。我的建议是在Arrayadapter中定义一个getCustomView方法。例如,一个简单的代码必须像它一样:
libzmq.so.4