国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > 综合技术 > [置顶] Android PopuWindow 导航链级筛选

[置顶] Android PopuWindow 导航链级筛选

来源:程序员人生   发布时间:2014-12-18 08:25:54 阅读次数:2874次

效果图:



代码

PopuWindowWidget

package com.example.checklistview; import android.annotation.SuppressLint; import android.content.Context; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.PopupWindow; @SuppressLint("ViewConstructor") public class PopuWindowWidget{ private static PopuWindowWidget popuWindow=null; private Context context; public PopuWindowWidget(Context context){ this.context=context; } public static PopuWindowWidget getInstance(Context context){ if(popuWindow==null){ popuWindow=new PopuWindowWidget(context); } return popuWindow; } public void onCreatePopuWindow(View view,PopuWindowListener listener){ PopupWindow pop=new PopupWindow(view,LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT); pop.setOutsideTouchable(false); pop.setFocusable(false); pop.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.background_trans)); listener.initialization(pop); } }
package com.example.checklistview; import android.widget.PopupWindow; public interface PopuWindowListener{ void isShow(boolean isShow,String message); void initialization(PopupWindow popuWindow); void onClickItem(Object obj); }

PopuWindowView:

package com.example.checklistview; import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.example.checklistview.CheckAdapter.NameOnClickListener; public class PopuWindowView implements NameOnClickListener{ private static PopuWindowListener listener; private View view; private Activity activity; private TextView tv; private ListView listView_bar; private ListView listView_data; private ArrayList<CheckBean> data=null; private ArrayList<CheckBean> bar=null; private HashMap<Integer, ArrayList<CheckBean>> map=new HashMap<Integer, ArrayList<CheckBean>>(); private HashMap<String,String> checkString=new HashMap<String,String>(); private CheckAdapter adapter_bar; private DataCheckAdapter adapter_data; private ViewHolder vhs; private TextView check_value; private Button sure; public static PopuWindowView getInstance(Activity activity,PopuWindowListener popuWindowListener,int layout){ listener=popuWindowListener; return new PopuWindowView(activity, layout); } public PopuWindowView(Activity activity,int layout){ this.view=activity.getLayoutInflater().inflate(layout, null); this.activity=activity; initialization(); } private void initialization() { // TODO Auto-generated method stub check_value=(TextView)view.findViewById(R.id.TextView_check_value); sure=(Button)view.findViewById(R.id.sure); listView_bar=(ListView)view.findViewById(R.id.action_bar); listView_data=(ListView)view.findViewById(R.id.listview_data); initData(); adapter_bar=new CheckAdapter(activity, bar,this); adapter_data=new DataCheckAdapter(activity, map.get(0),this); listView_bar.setAdapter(adapter_bar); listView_data.setAdapter(adapter_data); sure.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub listener.isShow(false, checkString.toString()); } }); } private void initData() { // TODO Auto-generated method stub bar=new ArrayList<CheckBean>(); CheckBean cb0=new CheckBean(0,"发布时间",true); CheckBean cb1=new CheckBean(1,"期望月薪",false); CheckBean cb2=new CheckBean(2,"工作经验",false); bar.add(cb0); bar.add(cb1); bar.add(cb2); data=new ArrayList<CheckBean>(); CheckBean dcb0=new CheckBean(0,"所有",false); CheckBean dcb1=new CheckBean(1,"今天",false); CheckBean dcb2=new CheckBean(2,"最近3天",false); CheckBean dcb3=new CheckBean(3,"最近1周",false); CheckBean dcb4=new CheckBean(4,"最近1个月",false); data.add(dcb0); data.add(dcb1); data.add(dcb2); data.add(dcb3); data.add(dcb4); map.put(0, data); data=new ArrayList<CheckBean>(); CheckBean dcb01=new CheckBean(0,"面议",false); CheckBean dcb11=new CheckBean(1,"3000元以下",false); CheckBean dcb21=new CheckBean(2,"3000⑸000元",false); CheckBean dcb31=new CheckBean(3,"5000⑻000元",false); CheckBean dcb41=new CheckBean(4,"8000⑴0000元",false); CheckBean dcb51=new CheckBean(5,"10000元以上",false); data.add(dcb01); data.add(dcb11); data.add(dcb21); data.add(dcb31); data.add(dcb41); data.add(dcb51); map.put(1, data); data=new ArrayList<CheckBean>(); CheckBean dcb02=new CheckBean(0,"不限",false); CheckBean dcb12=new CheckBean(1,"无工作经验",false); CheckBean dcb22=new CheckBean(2,"1年以下",false); CheckBean dcb32=new CheckBean(3,"1⑶年工作经验",false); CheckBean dcb42=new CheckBean(4,"3⑸年工作经验",false); CheckBean dcb52=new CheckBean(5,"5⑴0年工作经验",false); CheckBean dcb62=new CheckBean(6,"10年以上工作经验",false); data.add(dcb02); data.add(dcb12); data.add(dcb22); data.add(dcb32); data.add(dcb42); data.add(dcb52); data.add(dcb62); map.put(2, data); data=new ArrayList<CheckBean>(); CheckBean dcb03=new CheckBean(0,"全部",false); CheckBean dcb13=new CheckBean(1,"全职",false); CheckBean dcb23=new CheckBean(2,"兼职",false); CheckBean dcb33=new CheckBean(3,"实习",false); data.add(dcb03); data.add(dcb13); data.add(dcb23); data.add(dcb33); map.put(3, data); } public View getView(){ return view; } @Override public void callbackPosition(int type,int position) { // TODO Auto-generated method stub if(type==1){ for (int i = 0; i < adapter_bar.getList().size(); i++) { if(adapter_bar.getList().get(i).getId()==position){ adapter_bar.getList().get(i).setCheck(true); }else{ adapter_bar.getList().get(i).setCheck(false); } } adapter_data.setList(map.get(position)); adapter_bar.notifyDataSetChanged(); adapter_data.notifyDataSetChanged(); listView_data.post(new Runnable() { @Override public void run() { // TODO Auto-generated method stub for (int i = 0; i < adapter_data.getList().size(); i++) { if(adapter_data.getList().get(i).isCheck()){ listView_data.setSelectionFromTop(i, 0); return; } } listView_data.setSelectionFromTop(0, 0); } }); }else if(type==2){ int index=⑴; for (int i = 0; i < adapter_data.getList().size(); i++) { if(adapter_data.getList().get(i).getId()==position){ Toast.makeText(activity, ":"+i, 100).show(); adapter_data.getList().get(i).setCheck(true); index=i; }else{ adapter_data.getList().get(i).setCheck(false); } } adapter_data.notifyDataSetChanged(); // int indexStart=⑴; for (int i = 0; i < adapter_bar.getList().size(); i++) { if(adapter_bar.getList().get(i).isCheck()){ indexStart=i; for (int j = 0; j < map.get(i).size(); j++) { if(j==index){ map.get(i).get(index).setCheck(true); }else{ map.get(i).get(j).setCheck(false); } } } } for (int i = 0; i < map.size(); i++) { for (int j = 0; j < map.get(i).size(); j++) { if(map.get(i).get(j).isCheck()){ checkString.put(adapter_bar.getList().get(i).getName(), map.get(i).get(j).getName()); } } } check_value.setText("您当前选中:"+checkString.toString()); } } }


资源下载地址:http://download.csdn.net/detail/anddroid_lanyan/8229077




生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生