我没有找到符合我要求的任何代码。在getview和getdropdown视图中我应用了字体,但更改未反映在我的设计中请提前解决我的问题。
public class HintSpinnerAdapter implements SpinnerAdapter, ListAdapter {
protected static final int PIVOT = 1;
protected SpinnerAdapter adapter;
protected Context context;
protected int hintLayout;
protected int hintDropdownLayout;
protected LayoutInflater layoutInflater;
public HintSpinnerAdapter(
SpinnerAdapter spinnerAdapter,
int hintLayout, Context context) {
this(spinnerAdapter, hintLayout, -1, context);
}
public HintSpinnerAdapter(SpinnerAdapter spinnerAdapter,
int hintLayout, int hintDropdownLayout, Context context) {
this.adapter = spinnerAdapter;
this.context = context;
this.hintLayout = hintLayout;
this.hintDropdownLayout = hintDropdownLayout;
layoutInflater = LayoutInflater.from(context);
}
@Override
public final View getView(int position, View convertView, ViewGroup parent) {
// This provides the View for the Selected Item in the Spinner, not
// the dropdown (unless dropdownView is not set).
if (position == 0) {
return getHintView(parent);
}
return adapter.getView(position - PIVOT, null, parent); // Could re-use
// the convertView if possible.
}
protected View getHintView(ViewGroup parent) {
return layoutInflater.inflate(hintLayout, parent, false);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
// Android BUG! http://code.google.com/p/android/issues/detail?id=17128 -
// Spinner does not support multiple view types
if (position == 0) {
return hintDropdownLayout == -1 ?
new View(context) :
getHintDropdownView(parent);
}
// Could re-use the convertView if possible, use setTag...
return adapter.getDropDownView(position - PIVOT, null, parent);
}
protected View getHintDropdownView(ViewGroup parent) {
return layoutInflater.inflate(hintDropdownLayout, parent, false);
}
@Override
public int getCount() {
int count = adapter.getCount();
return count == 0 ? 0 : count + PIVOT;
}
@Override
public Object getItem(int position) {
return position == 0 ? null : adapter.getItem(position - PIVOT);
}
@Override
public int getItemViewType(int position) {
return 0;
}
@Override
public int getViewTypeCount() {
return 1;
}
@Override
public long getItemId(int position) {
return position >= PIVOT ? adapter.getItemId(position - PIVOT) : position - PIVOT;
}
@Override
public boolean hasStableIds() {
return adapter.hasStableIds();
}
@Override
public boolean isEmpty() {
return adapter.isEmpty();
}
@Override
public void registerDataSetObserver(DataSetObserver observer) {
adapter.registerDataSetObserver(observer);
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
adapter.unregisterDataSetObserver(observer);
}
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int position) {
return position != 0; // Don't allow the 'hint' item to be picked.
}
}
我按照上面的链接提供的答案,但这对我没有用。我不知道该代码中有哪些更改可以解决我的问题。