2013-02-04 88 views
1

我目前正在Android中实现一个微调,并且无法获得两个数组与Spinner连接 - 当微调不扩展时,以及当它是一个时。扩展微调项目

因此,微调应该是这样的,当没有展开它: Small Spinner

当它展开的阵列连接到它从字符串到长版本的缩短版的变化。 Expanded Spinner

我已经想过改变阵列时微调被触摸,然后改变它回来时,它取消了,但我认为这将最终被凌乱,或以其他方式创建一个按钮,看起来像一个微调,这打开一个自定义的ListView对话框来充当一个自定义的Spinner,但是这看起来像是矫枉过正。有更容易的方法吗?

回答

1

你可以实现你自己的适配器来达到这个效果。重写getView()返回您的“展开”视图,并getDropDownView()返回您的“折叠”视图。不要忘记利用convertView。

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), 0, objects) { 
     @Override 
     public View getDropDownView(int position, View convertView, ViewGroup parent) { 
      //inflate and return the view you want to see as the non-expanded droplist 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      //inflate and return the expanded view 
     } 
    };