我正在使用自定义适配器使用自定义项填充微调器。 布局是一个下拉列表。
正如标题所说,我希望在我的微调器中有物品(代表类别)。 喜欢:意大利,法国,德国。 (例)。 每个项目都应该打开,然后是第二个带有城市的微调器(就像嵌套的微调器一样)。 喜欢:罗马,佛罗伦萨,米兰。 我希望它的外观和行为类似于Microsoft Windows底部菜单(XP,Vista,7)。
有可能吗? 任何人都可以帮忙吗?
哦......而且我的微调器位于抽屉DrawerLayout
内,它会使ListView
膨胀...只是为了增加一些复杂性;)
CustomSpinnerAdapter类
public class CustomSpinnerAdapterCity extends ArrayAdapter<SpinnerItem> {
Context context;
int layoutResID;
List<SpinnerItem> spinnerData;
protected LayoutInflater layoutInflater;
public CustomSpinnerAdapterCity(Context context, int layoutResourceID, int textViewResourceId, List<SpinnerItem> spinnerDataList) {
super(context, layoutResourceID, textViewResourceId, spinnerDataList);
this.context=context;
this.layoutResID=layoutResourceID;
this.spinnerData=spinnerDataList;
}
public CustomSpinnerAdapterCity(Context context, int layoutResourceID, List<SpinnerItem> spinnerDataList) {
super(context, layoutResourceID, spinnerDataList);
this.context=context;
this.layoutResID=layoutResourceID;
this.spinnerData=spinnerDataList;
layoutInflater = LayoutInflater.from(context);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return getCustomView(position, convertView, parent);
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
View row=convertView;
SpinnerHolder holder;
SpinnerItem mSpinnerItem =spinnerData.get(position);
if(row==null)
{
LayoutInflater inflater=((Activity)context).getLayoutInflater();
row=inflater.inflate(layoutResID, parent, false);
holder=new SpinnerHolder();
holder.current_city=(TextView)row.findViewById(R.id.current_city);
holder.current_city_description=(TextView)row.findViewById(R.id.current_city_description);
row.setTag(holder);
}
else
{
holder=(SpinnerHolder)row.getTag();
}
if(mSpinnerItem.getCurrentChoice()!=null)
{
holder.current_city.setText(mSpinnerItem.getCurrentChoice());
holder.current_city_description.setText(mSpinnerItem.getCurrentChoiceDescription());
}
return row;
}
public int getPosition(SpinnerItem s) {
return super.getPosition(s); //return position of the last value
}
@Override
public int getCount() {
return super.getCount()-3; // you dont display last item. It is used as hint.
}
public int getCountCertifiedonly() {
return super.getCount()-2; // you dont display last item. It is used as hint.
}
public int getCountVIPonly() {
return super.getCount()-1; // you dont display last item. It is used as hint.
}
public int getCountCityNone() {
return super.getCount()-1; // you dont display last item. It is used as hint.
}
private static class SpinnerHolder
{
TextView current_city,current_city_description;
}
}
SpinnerItem类
public class SpinnerItem implements Item{
String choice;
String choice_description;
Boolean isSection = false;
public SpinnerItem(String choice, String choice_description, Boolean isSection) {
super();
this.choice=choice;
this.choice_description=choice_description;
this.isSection=isSection;
}
public String getCurrentChoiceDescription() {
return choice_description;
}
public void setCurrentChoiceDescription(String choice_description) {
this.choice_description = choice_description;
}
public String getCurrentChoice() {
return choice;
}
public void setCurrentChoice(String choice) {
this.choice = choice;
}
@Override
public boolean isSection() {
return isSection;
}
}
答案 0 :(得分:0)
您不需要列表视图,您可以使用导航抽屉和菜单组合。
查看详情
https://medium.com/ribot-labs/exploring-the-new-android-design-support-library-b7cda56d2c32