Back to project page markj.
The source code is released under:
GNU Lesser General Public License
If you think the Android project markj listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.markjmind.mobile.api.android.ui.view; /*w w w. j av a 2 s . c o m*/ import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import com.markjmind.mobile.api.android.controller.Jwc; import com.markjmind.mobile.api.android.ui.JwGroup; import com.markjmind.mobile.api.android.ui.JwOnGroupSelect; public class JwDropDown extends JwBaseDropDown{ public interface ItemInit{ public void init(int index,String itemKey, View itemView, JwGroup jg); } private ViewGroup boarder; private ViewGroup parentsView; private JwGroup jg; private JwOnGroupSelect groupSelect; private View onClickView; private ItemInit itemInit; public JwDropDown(Context context) { super(context); parentsView = new LinearLayout(getContext()); ((LinearLayout)parentsView).setOrientation(LinearLayout.VERTICAL); parentsView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); boarder = parentsView; jg = new JwGroup(); jg.setReselected(true); jg.setOnGroupSelect(new JwOnGroupSelect() { @Override public void selected(View v, String itemKey, int index, Object param) { dismiss(); } @Override public void deselected(View v, String itemKey, int index, Object param) { } }); } public JwDropDown(Context context,View onClickView) { this(context); this.onClickView = onClickView; this.onClickView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { show(); } }); } /** * Item???? ?????. */ private void initItems(){ if(itemInit!=null){ for(int i=0;i<jg.size();i++){ String itemKey = jg.getName(i); View itemView = jg.getView(i); itemInit.init(i, itemKey, itemView, jg); } } } /** * ?? Item??? layout?? ?? ???? ????? ????. * @param ItemInit */ public void setItemsInit(ItemInit itemInit){ this.itemInit = itemInit; } /** * Item?? ???? View? ????. * @param view Item?? ???? View * @param itemKey itemKey? * @param param select? ?????? param */ public void addItem(View view,String itemKey, Object param){ parentsView.addView(view); view.setClickable(true); jg.add(itemKey, view, param); } /** * Item?? ???? View? ????.<br> * select? ?????? param??? null??? ????. * @param view Item?? ???? View * @param itemKey itemKey? */ public void addItem(View view,String itemKey){ this.addItem(view, itemKey, null); } /** * Item?? ???? View? ????. * @param R_layout_id Item?? ???? layout id * @param itemKey itemKey? * @param param select? ?????? param */ public void addItem(int R_layout_id, String itemKey, Object param){ View view = Jwc.getViewInfalter(R_layout_id, getContext()); this.addItem(view, itemKey, param); } /** * Item?? ???? View? ????.<br> * select? ?????? param??? null??? ????. * @param R_layout_id Item?? ???? layout id * @param itemKey itemKey? */ public void addItem(int R_layout_id, String itemKey) { this.addItem(R_layout_id, itemKey, null); } /** * Item?? ???? View? ????.<br> * select? ?????? itemKey? null??? ????.<br> * select? ?????? param??? null??? ????. * @param R_layout_id Item?? ???? layout id */ public void addItem(int R_layout_id) { this.addItem(R_layout_id, null, null); } /** * Item??? ?????. * @param itemKey ???? Item itemKey */ public void select(String itemKey){ jg.select(itemKey); } /** * Item??? ?????. * @param index ???? Item index */ public void select(int index){ jg.select(index); } /** * ????? ???? Item?? ??? select/deselect? ???? ????? * @param groupSelect Item?? ?? select listener */ public void setOnSelected(JwOnGroupSelect groupSelect){ this.groupSelect = groupSelect; jg.setOnGroupSelect(new JwOnGroupSelect() { @Override public void selected(View v, String itemKey, int index, Object param) { if(JwDropDown.this.groupSelect!=null){ JwDropDown.this.groupSelect.selected(v, itemKey, index, param); } dismiss(); } @Override public void deselected(View v, String itemKey, int index, Object param) { if(JwDropDown.this.groupSelect!=null){ JwDropDown.this.groupSelect.deselected(v, itemKey, index, param); } } }); } /** * item??? size? ????. */ public int getItemSize(){ return jg.size(); } /** * BoarderLayout??? ????. * @param R_layout_id boarder layout ID * @param add_view_group_id boarder ???? Item? ??? ViewGourp ID */ public void setBoarderLayout(ViewGroup boarder, int add_view_group_id){ this.boarder = boarder; this.boarder.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); this.parentsView = (ViewGroup)this.boarder.findViewById(add_view_group_id); } /** * BoarderLayout??? ????. * @param R_layout_id boarder layout ID * @param add_view_group_id boarder ???? Item? ??? ViewGourp ID */ public void setBoarderLayout(int R_layout_id, int add_view_group_id){ ViewGroup mainView = (ViewGroup)Jwc.getViewInfalter(R_layout_id, getContext()); setBoarderLayout(mainView,add_view_group_id); } /** * ????? Boarder??? Layout??? ????. * @return Boarder ViewGroup */ public ViewGroup getBoarderLayout(){ return boarder; } /** * dropdown popup??? ?????. */ public void show(){ setMainContentView(boarder); initItems(); super.show(onClickView); } /** * onClickView? ???? * dropdown popup??? ?????. * @param onClickView */ public void show(View onClickView){ setMainContentView(boarder); initItems(); super.show(onClickView); } /** * ?????? Item? ???????? ??? ??<br> * isReselected??? defalut? false???? * @param isReselected */ public void setReselected(boolean isReselected){ jg.setReselected(isReselected); } }