Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android PopuWindow 導航鏈級篩選

Android PopuWindow 導航鏈級篩選

編輯:關於Android編程

效果圖:

\\\


代碼

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 data=null;
	private ArrayList bar=null;
	private HashMap> map=new HashMap>();
	private HashMap checkString=new HashMap();


	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 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 dcb0=new CheckBean(0,"所有",false);
		CheckBean dcb1=new CheckBean(1,"今天",false);
		CheckBean dcb2=new CheckBean(2,"最近三天",false);
		CheckBean dcb3=new CheckBean(3,"最近一周",false);
		CheckBean dcb4=new CheckBean(4,"最近一個月",false);
		data.add(dcb0);
		data.add(dcb1);
		data.add(dcb2);
		data.add(dcb3);
		data.add(dcb4);
		map.put(0, data);


		data=new ArrayList();
		CheckBean dcb01=new CheckBean(0,"面議",false);
		CheckBean dcb11=new CheckBean(1,"3000元以下",false);
		CheckBean dcb21=new CheckBean(2,"3000-5000元",false);
		CheckBean dcb31=new CheckBean(3,"5000-8000元",false);
		CheckBean dcb41=new CheckBean(4,"8000-10000元",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 dcb02=new CheckBean(0,"不限",false);
		CheckBean dcb12=new CheckBean(1,"無工作經驗",false);
		CheckBean dcb22=new CheckBean(2,"1年以下",false);
		CheckBean dcb32=new CheckBean(3,"1-3年工作經驗",false);
		CheckBean dcb42=new CheckBean(4,"3-5年工作經驗",false);
		CheckBean dcb52=new CheckBean(5,"5-10年工作經驗",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 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=-1;
			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=-1;
			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




  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved