我有一个带有自定义适配器的列表视图。在列表视图中是具有不同 XML 布局的不同元素。其中之一是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.myapp"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<include layout="@layout/list_row_top" />
<antistatic.spinnerwheel.WheelHorizontalView
android:id="@+id/wP_pollrate"
app:visibleItems="4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
在适配器中,我有如下所示的 getView 方法:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ConfigItem c = configItems.get(position);
if(c instanceof ConfigFilePicker) {
if (v == null) {
LayoutInflater vi = (LayoutInflater)appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_row_config_picker, null);
}
TextView topLabel = (TextView) v.findViewById(R.id.tV_list_row_top_label);
TextView configFileName = (TextView) v.findViewById(R.id.tV_list_row_config);
topLabel.setText(c.getTopLabel());
configFileName.setText(((ConfigFilePicker) c).getChoosenFileName());
}
else if(c instanceof ConfigPollrate) {
if (v == null) {
LayoutInflater vi = (LayoutInflater)appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_row_config_pollrate, null);
}
TextView topLabel = (TextView) v.findViewById(R.id.tV_list_row_top_label);
topLabel.setText(c.getTopLabel());
/** Setting adapter for picker wheel */
AbstractWheel wheel = (AbstractWheel) v.findViewById(R.id.wP_wheel);
ArrayWheelAdapter<String> wheelAdapter =
new ArrayWheelAdapter<String>(this.appContext, ((ConfigPollrate) c).getValues());
/** Setting layout and finally the adapter to the view */
wheelAdapter.setItemResource(R.layout.wheel_text_centered_dark_back);
wheelAdapter.setItemTextResource(R.id.text);
wheel.setViewAdapter(pollrateAdapter);
}
return v;
}
如您所见,我正在使用antistatic.spinnerwheel
从该项目android-spinnerwheel调用的特殊选择器轮。
问题是这AbstractWheel wheel = (AbstractWheel) v.findViewById(R.id.wP_wheel);
总是导致一个空指针。id 被发现了。
我做错了什么?