码迷,mamicode.com
首页 > 其他好文 > 详细

ListView中Button事件

时间:2014-07-08 13:15:00      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:listview   button   响应   


为了解决ListView中Item里的Button独立事件响应,可以采用以下方法:

在BaseAdapter的getview里添加加粗代码:


<span style="font-size:14px;">@Override
	public View getView(int position, View view, ViewGroup arg2) {
		view = layoutInflater.from(context).inflate(
				R.layout.sport_user_list_item, null);

		TextView text1 = (TextView) view.findViewById(R.id.user_name);
		TextView text2 = (TextView) view.findViewById(R.id.user_grade);
		
		Button button1 = (Button) view.findViewById(R.id.challenger_btn);

		text1.setText("姓名");
		text2.setText("等级");

		String user = sportUserList.get(position).getUser();
		UserCode[] codes = challengeDBAdapter.queryOneData(user);

		if (codes == null) {
			text6.setVisibility(8);
			<span style="font-size:18px;"><strong>button1.setTag(position + "");</strong></span>

			button1.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {

					<strong><span style="font-size:18px;">int temp = Integer.parseInt(v.getTag().toString()) ;</span></strong>
// 设置验证码
SetChallengeCodeThread codeThread = new SetChallengeCodeThread(temp);
codeThread.start();

				}
			});
		} else {
			text6.setText(codes[0].getCode() + "");
			button1.setVisibility(8);
		}

		return view;
	}
</span>




ListView中Button事件,布布扣,bubuko.com

ListView中Button事件

标签:listview   button   响应   

原文地址:http://blog.csdn.net/pengkv/article/details/37500673

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!