我正在尝试将 android actionbar spinner 自定义为类似于 google currents 应用程序的东西。基本上,只有“副标题”应该反映我从微调器中选择的内容,而“标题”保持不变。我知道需要创建一个自定义微调器,并且我必须覆盖 getView()
andgetDropDownView()
方法。但是我在这里对如何正确覆盖这些方法感到非常困惑。有人可以将我推向正确的方向吗?我希望我把我的问题说清楚了。
(来源:androidcowboy.com)
下面给出的是我的代码。
public class CustomSpinnerAdapter extends BaseAdapter {
private LayoutInflater inflater;
private final Context context;
private final String[] dropDown;
private final String mainText;
private final String subText;
public CustomSpinnerAdapter(Context context,
String mainText, String subText,String[] dropDown) {
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.mainText=mainText;
this.subText=subText;
this.context = context;
this.dropDown=dropDown;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View actionBarView = inflater.inflate(R.layout.custom_spinner, null);
TextView textView = (TextView) actionBarView
.findViewById(R.id.custom_spinner_textview);
textView.setText(mainText);
return actionBarView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View dropDownView = inflater.inflate(R.layout.custom_spinner, null);
TextView dropDownTextView = (TextView) dropDownView
.findViewById(R.id.custom_spinner_dropdown_textview);
dropDownTextView.setText(dropDown[position]);
return dropDownView;
}
}