当 diffspinner 试图充气时出现充气错误。这是我下面的代码
我创建微调器并将适配器应用到它的主要活动:
diffSpinner= (Spinner) findViewById(R.id.settingsSpinner1); difficult_adapter dAdapter = new difficult_adapter(getApplication().getBaseContext(),getResources().getStringArray(R.array.difficultyArray)) {}; diffSpinner.setAdapter(dAdapter); diffSpinner.setSelection(settingsArray[1]);
我的难度适配器:
public class difficult_adapter extends BaseAdapter {
Context context;
String[] diffNames;
LayoutInflater inflter;
public difficult_adapter(Context applicationContext, String[] diffNames) {
this.context = applicationContext;
this.diffNames = diffNames;
inflter = (LayoutInflater.from(applicationContext));
}
@Override
public int getCount() {
return diffNames.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflter.inflate(R.layout.difficultyspinner, null);
TextView names = (TextView) view.findViewById(R.id.difftextView);
names.setText(diffNames[i]);
//names.setTextColor(R.attr.textColor);
//names.setBackgroundColor(R.attr.backColor);
return view;
}
}
难度微调器的布局:
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/difftextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
style="@style/diffspinneritem"
/>
和风格:
<style name="diffspinneritem" parent="@android:style/Widget.Holo.DropDownItem.Spinner">
<item name="android:textColor">?attr/textColor</item>
</style>