基于上一篇写的SimplePairListPopupWindow

系统 1460 0
这次使用Pair<F,S>实现一个简单的SimplePairListPopupWindow,还是为了快速迭代,谅解

    
import java.util.ArrayList;

import android.content.Context;
import android.util.Pair;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.mb.bgfitting.App;
import com.mb.bgfitting.CommonAdapter;
import com.mb.bgfitting.ViewHolder;
import com.mb.bgfitting.app.R;

/**
 * 
 * @author pythoner
 * 
 */
public class SimplePairListPopupWindow<F,S> extends PopupWindow {

	private Context context;
	private CommonAdapter<Pair<F,S>> adapter;
	private ArrayList<Pair<F,S>> beans;
	public SimplePairListPopupWindow(Context context, View view, int width,ArrayList<Pair<F,S>> b) {
		super(view, width, LayoutParams.WRAP_CONTENT, true);
		this.context = context;
		this.beans = b;
		this.setBackgroundDrawable(App.res.getDrawable(R.drawable.bg_popupwindow));
		this.setOutsideTouchable(true);
		this.setAnimationStyle(android.R.style.Animation_Dialog);
		// this.update();
		// this.setTouchable(true);
		// this.setFocusable(false);

		ListView listView = (ListView) view.findViewById(R.id.listView);
		listView.setAdapter(adapter = new CommonAdapter<Pair<F,S>>(context, beans,R.layout.item_for_popupwindow_simple) {
			@Override
			public void setValues(ViewHolder helper, Pair<F,S> item, int position) {
				helper.setText(R.id.item_0, item.second.toString());
			}
		});

		listView.setOnItemClickListener(new ListView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> pearnt, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				dismiss();
				if (onItemClickListener != null) {
					onItemClickListener.onItemClick(position,beans.get(position));
				}
			}
		});

	}

	public interface OnItemClickListener<F,S> {
		void onItemClick(int position, Pair<F,S> pair);
	}

	OnItemClickListener<F,S> onItemClickListener;

	public void setOnItemClickListener(OnItemClickListener<F,S> onItemClickListener) {
		this.onItemClickListener = onItemClickListener;
	}

}

  



基于上一篇写的SimplePairListPopupWindow<F,S>


用法:
    
private void showSimplePopupWindow(View v){
		ArrayList<Pair<Integer, String>> beans = new ArrayList<Pair<Integer, String>>();
		beans.add(new Pair<Integer, String>(0, "当天未完成"));
		beans.add(new Pair<Integer, String>(1, "当天全部"));
		beans.add(new Pair<Integer, String>(2, "当天自己"));
		beans.add(new Pair<Integer, String>(3, "历史查询"));
		beans.add(new Pair<Integer, String>(4, "交易查询"));
		
		View view = LayoutInflater.from(context).inflate(R.layout.popupwindow_simple, null);
		final SimplePairListPopupWindow<Integer, String> popupWindow = new SimplePairListPopupWindow<Integer, String>(context,view, (int)App.res.getDimension(R.dimen.popupwindow_width), beans);
		popupWindow.showAsDropDown(v, 0, 0);
		popupWindow.setOnItemClickListener(new SimplePairListPopupWindow.OnItemClickListener<Integer, String>() {

			@Override
			public void onItemClick(int position, Pair<Integer, String> pair) {
				// TODO Auto-generated method stub
				
			}
		});
	}

  

基于上一篇写的SimplePairListPopupWindow


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论