此问题在使用Spinner绑定布局时报错;
ArrayAdapter<String> arrayAdapter =new ArrayAdapter<String>(getContext(), R.layout.spinner_item2,ListData());
arrayAdapter.setDropDownViewResource(R.layout.spinner_item);
spinner.setAdapter(arrayAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
HiddenKey();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
ArrayAdapter所绑定的布局是 R.layout.spinner_item2;
下面是R.layout.spinner_item2的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
将R.layout.spinner_item2的布局代码更改为:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:textColor="@color/text_color_smallblack"
/>
重点在于:xmlns:android=“http://schemas.android.com/apk/res/android”;
ArrayAdapter所需要的布局均像此更改即可;
运行之后,正常;