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事件

时间: 2024-07-31 03:15:31

ListView中Button事件的相关文章

Android ListView中Button事件 点击冲突问题的解决方案

今天遇到一个问题:在设置listview  自定义adapter的时候 ,点击item有点击效果,然后点击item布局文件中的某个button 的时候  也同时触发了listview的点击效果, 解决方案是: 1.在adapter布局文件中添加 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk

Android实战简易教程-第十五枪(实现ListView中Button点击事件监听)

1.main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" androi

ListView中button监听器 设置 及 优化

在应用开发中常常会用到ListView,而且每个Item里面都会有button之类的须要进行事件监听的控件.在给button加入OnClickListener的时候,一開始非常下意识的会想在ListView的adapter的getView方法中找到每个Button并new一个OnClickListener分配给这个button. 可是当数据量非常大的时候,new出来这么多个监听器势必会对内存造成一定的压力.并且每一个Listener的功能全然一样,Listener里面所需知道的,只是是调用者所在

flex中Button事件中的e.target

关于flex中的Button事件中的e.target. 今天想在事件中调用模块中的对象通过e.target获取单击的这个Button对象,但是可能是使用var btn:Button = e.target as Button居然会使得btn为空,这就让我很奇怪了.最后终于发现了,原来是因为主程序中获取的是spark这个包里面的<s:Button />对象,而模块中是使用 <mx:Button />这个对象而导致错误.解决方法: 将模块里面的<mx:Button />改为&

listview中button抢占焦点问题

解决办法Item xml 根节点添加 android:descendantFocusability="blocksDescendants" Button 设置 android:focusable="false" 这样点击Button 和ListView Item 可以分别响应自己的点击事件 开发中很常见的一个问题,项目中的listview不仅仅是简单的文字,常常需要自己定义listview,自己的Adapter去继承BaseAdapter,在adapter中按照需求

winform实现listview中combox

一.概要 因为要在项目中要在ListView中实现下拉框选择,用DataGrid的话,一个不美观,二个绑定数据麻烦,参考网上一种做法,就是单击ListView时,判断单击的区域,然后将Combox控件显示单击的区域,以模拟效果,很少写winform,写的不好,望大家不要笑话. 二.准备控件 先在容器中拖入一个ListView控件和Combox控件,然后设置Combox控件的Visible属性为False,即隐藏Combox控件,如图: 随便填充点数据到ListView和Combox中,如下: 1

Android学习之解决ListView中item点击事件和item中Button点击事件冲突问题

在ListView中添加Button后,如果只是单纯的加入而不加限制的话,ListView的onClick点击事件没有响应,因为Button获取了item的焦点,想要两者都可点击,需要加上如下限制: 在ListView的适配器中的布局文件中添加: (1)在布局文件的根元素上中添加属性android:descendantFocusability="blocksDescendants" (2)在Button中添加属性android:focusable="false"和a

Xamarin.Forms listview中的button按钮,实现带着参数返回上一级页面

今天在做列表显示的时候遇到一个问题,就是在ListView中如何才能让一个button的按钮工作并且包含参数呢? 其实有点类似于rep里的控件无法起获取一样.在Xamarin中,当你button绑定事件并不包含在listview的数据源中,那么这个按钮的事件便是无效的. 那么该怎么解决呢?找了一下午终于找到了解决方案 xaml: <AbsoluteLayout IsVisible="True" HorizontalOptions="EndAndExpand"&

android ListView中的Item有Button时候点击异常处理

1.当ListView中有Button的时候往往会遇到很多问题,比较常见的一个问题是: 假设:在ListView中有N个Item当点击其中某个Item中的Button的时候,需要改变当前Button的状态,在你点击以后确实最后一个Item的Button的状态改变了,不管点击哪一个Button都是最后一个 Item的中的Button的状态被改变了,这里涉及到ListView重绘的问题. 要解决上面的问题的方法是将点击的监听事件提出来进行封装,在用就可以解决上述问题了. 给个示例代码: 在ListV