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>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值