欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android自定義單選多選下拉列表的實(shí)例代碼

 更新時(shí)間:2017年07月30日 10:25:13   作者:Fun_He  
本篇文章主要介紹了Android自定義單選多選下拉列表的實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

發(fā)瘋的產(chǎn)品要做一個(gè)可以單選和多選的下拉列表,陪你玩玩吧。

直接上效果:

實(shí)現(xiàn)方案:

我的思路是自定義一個(gè)類繼承PopupWindow,里面的選項(xiàng)采用Listview,再結(jié)合一些動(dòng)畫(huà)來(lái)實(shí)現(xiàn)。

核心代碼:

public class MultiSelectPopupWindows extends PopupWindow {

  private Context context;
  private View parent;
  private List<Search> data;
  private int yStart;
  private SearchPopupWindowsAdapter adapter;

  public MultiSelectPopupWindows(Context context, View parent, int yStart, List<Search> data) {
    this.context = context;
    this.parent = parent;
    this.yStart = yStart;
    this.data = data;
    initView();
  }

  private void initView() {
    View view = View.inflate(context, R.layout.popupwindows_multiselect, null);
    view.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_in_slow));
    LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayout_selector);
    linearLayout.startAnimation(AnimationUtils.loadAnimation(context, R.anim.list_top_in));
    ListView listView = (ListView) view.findViewById(R.id.listView_selector);

    setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    setBackgroundDrawable(new BitmapDrawable());
    setFocusable(true);
    setOutsideTouchable(true);
    setContentView(view);
    showAtLocation(parent, Gravity.TOP, 0, DensityUtil.dip2px(context, yStart));
    update();

    initListView(listView, data);
  }

  private void initListView(ListView listView, List<Search> data) {
    adapter = new SearchPopupWindowsAdapter(context);
    adapter.setItems(data);
    listView.setAdapter(adapter);
  }

  public List getItemList() {
    return adapter.getItemList();
  }

}
 

項(xiàng)目源碼:https://github.com/hfrommane/MultiSelectPopupWindows

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論