关于ListView点击无效,item无法相应点击事件的问题,网上有很多, 大致可分为俩种情况, 一种是 item中存在 ImageButton 等可以点击的组件,这会抢先获得ListView的焦点. 从而导致item点击失效......等等网上好多,不过今天我记录的是另一种情况, 就是ListView中只有TextView 其他什么都没有 ,还失效的情况, 用网上的两种常见的方法,都无济于事.

经过几番的测试, 发现是在适配器的getView中处理TextView的时候,调用了适配器的notifyDataSetChanged. 在notifyDataSetChanged之后导致item失去焦点.

之前,碰到过类似的问题, 就是由于在对话框中调用了适配器更新方法notifyDataSetChanged导致Activity失去焦点,影响屏蔽物理返回键的效果.  至于这个notifyDataSetChanged更新以后,哪个组件获得了焦点.还没有研究.先记录下,研究以后在补充这文章.

下面是摘自网络的相关点击item失效问题的解决方法.仅供参考.


最近有人问我,在Android里:

在自定义listView里面有按钮,然后setItemClickListener时不响应,网上很多关于这个的,但我都试过,貌似都解决不了。

其实刚开始学Android接触ListView时我也遇到此问题,在网上到处搜也难以找到相关解决方案,原因之一是网上原创文章少,转载居多,很多文章都雷同;原因之二在于自己英语不好,不敢上外文论坛去找。

后来经过自己的慢慢摸索终于解决了这个问题。

当朋友问我时,我一番简单讲解加几张代码截图就给他解决问题啦~

废话不多说,先上源代码:源代码

代码片段:

main.xml

[html] view plaincopyprint?

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
<ListView
android:id="@+id/lv_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/numxback"
android:cacheColorHint="#00000000"
android:drawSelectorOnTop="false"
android:fadingEdge="none"
android:fastScrollEnabled="true"
android:focusable="false"
android:divider="@null"
android:focusableInTouchMode="true"
android:listSelector="@drawable/itemselected" />
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
<ListView
android:id="@+id/lv_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/numxback"
android:cacheColorHint="#00000000"
android:drawSelectorOnTop="false"
android:fadingEdge="none"
android:fastScrollEnabled="true"
android:focusable="false"
android:divider="@null"
android:focusableInTouchMode="true"
android:listSelector="@drawable/itemselected" />

在main布局里加入了一个列表控件,ListView,它的各个属性在此处不是重点,这里就不多说,看不懂的读者自己去网上搜吧!

datalist.xml

[html] view plaincopyprint?

<?xml version="1.0" encoding="utf-8"?>

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<TextView
android:id="@+id/tv_num"
android:layout_width="wrap_content"
android:layout_height="60px"
android:layout_centerVertical="true"
android:background="@drawable/number"
android:gravity="center"
android:paddingLeft="5px"
android:paddingRight="8px"
android:textColor="@android:color/white"
android:textSize="24sp" /> <ImageButton
android:id="@+id/ib_edit"
android:layout_width="60px"
android:layout_height="60px"
android:layout_alignParentRight="true"
android:background="@drawable/edit"
<SPAN style="COLOR: #ff0000">android:onClick="OnItemEditClick"

android:paddingRight="5px" />

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<TextView
android:id="@+id/tv_numx"
android:layout_width="150px"
android:layout_height="60px"
android:layout_toRightOf="@+id/tv_num"
android:background="@drawable/number"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="24sp" /> <TextView
android:id="@+id/tv_numy"
android:layout_width="150px"
android:layout_height="60px"
android:layout_toRightOf="@id/tv_numx"
android:layout_toLeftOf="@id/ib_edit"
android:background="@drawable/number"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="24sp" />

<?xml version="1.0" encoding="utf-8"?>

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<TextView
android:id="@+id/tv_num"
android:layout_width="wrap_content"
android:layout_height="60px"
android:layout_centerVertical="true"
android:background="@drawable/number"
android:gravity="center"
android:paddingLeft="5px"
android:paddingRight="8px"
android:textColor="@android:color/white"
android:textSize="24sp" /> <ImageButton
android:id="@+id/ib_edit"
android:layout_width="60px"
android:layout_height="60px"
android:layout_alignParentRight="true"
android:background="@drawable/edit"
android:onClick="OnItemEditClick"
android:paddingRight="5px" /> <TextView
android:id="@+id/tv_numx"
android:layout_width="150px"
android:layout_height="60px"
android:layout_toRightOf="@+id/tv_num"
android:background="@drawable/number"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="24sp" /> <TextView
android:id="@+id/tv_numy"
android:layout_width="150px"
android:layout_height="60px"
android:layout_toRightOf="@id/tv_numx"
android:layout_toLeftOf="@id/ib_edit"
android:background="@drawable/number"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="24sp" />

列表控件单项布局,在里面加入了三个TextView,一个ImageButton,显示时三个TextView 在前面,最后一个ImageButton。

之前说到的按钮点击事件在Activity里用button.setOnClickListener的方式实现时会屏蔽/占用ListView单项单击事件,这里就在布局里加了一个android:onClick="OnItemEditClick",用于绑定按钮点击事件,然后在java代码中实现这个方法,记得须有一个View类型的参数。

MainActivity.java

[java] view plaincopyprint?

package com.test.customlistview;

import java.util.ArrayList;



import java.util.HashMap;

import android.os.Bundle;



import android.os.Handler;



import android.os.Message;



import android.app.Activity;



import android.app.AlertDialog;



import android.content.DialogInterface;



import android.content.DialogInterface.OnClickListener;



import android.view.View;



import android.widget.AdapterView;



import android.widget.ImageButton;



import android.widget.ListView;



import android.widget.RelativeLayout;



import android.widget.SimpleAdapter;



import android.widget.TextView;



import android.widget.Toast;



import android.widget.AdapterView.OnItemLongClickListener;

public class MainActivity extends Activity {

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
ListView dataListView;
SimpleAdapter listAdapter;
ArrayList<HashMap<String, Object>> list;
private int location;
Handler mHandler = new Handler() { @Override
public void handleMessage(Message msg) {
if (msg.arg1 == 1) { } else if (msg.arg1 == 2) { } else if (msg.arg1 == 4) {
if (msg.what == 1) {
dataListView.getChildAt(msg.arg2).setBackgroundResource(
R.drawable.itemback);
}
}
super.handleMessage(msg);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dataListView = (ListView) findViewById(R.id.lv_list);
list = new ArrayList<HashMap<String, Object>>();
int count = 20;
HashMap<String, Object> map;
for (int i = 1; i <= count; i++) {
map = new HashMap<String, Object>();
map.put("num", i+ "");
map.put("a1", "²=");
map.put("a2", ""+i*i);
list.add(map);
}
listAdapter = new SimpleAdapter(this, list, R.layout.datalist,
new String[] { "num", "a1", "a2" }, new int[] { R.id.tv_num,
R.id.tv_numx, R.id.tv_numy });
dataListView.setAdapter(listAdapter);
dataListView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View view,
int position, long id) {
location = position;
final View nowView = (View) view.findViewById(R.id.ib_edit);
Toast.makeText(getBaseContext(), "location=" + location, 2000)
.show();
OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
Toast.makeText(getBaseContext(), "编辑", Toast.LENGTH_LONG).show();
} else if (which == 1) {
Toast.makeText(getBaseContext(), "删除", Toast.LENGTH_LONG).show();
}
}
};
dataListView.getChildAt(location).setBackgroundResource(
R.drawable.item_frame);
Message message = new Message();
message.arg1 = 4;
message.arg2 = location;
message.what = 1;
mHandler.sendMessageDelayed(message, 500);
String[] Menu = { "编辑", "删除" }; new AlertDialog.Builder(MainActivity.this).setItems(Menu,
listener).show();
return false;
}
});
} public void OnItemEditClick(View v) {
RelativeLayout layout = (RelativeLayout) v.getParent();
TextView tv1=(TextView)layout.findViewById(R.id.tv_num);
TextView tv2=(TextView)layout.findViewById(R.id.tv_numx);
TextView tv3=(TextView)layout.findViewById(R.id.tv_numy);
ImageButton ib=(ImageButton)layout.findViewById(R.id.ib_edit);
String str="按钮"+tv1.getText()+"点击啦n"+tv1.getText()+tv2.getText()+tv3.getText();
Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
}

}



package com.test.customlistview;

import java.util.ArrayList;

import java.util.HashMap;

import android.os.Bundle;

import android.os.Handler;

import android.os.Message;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.content.DialogInterface.OnClickListener;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ImageButton;

import android.widget.ListView;

import android.widget.RelativeLayout;

import android.widget.SimpleAdapter;

import android.widget.TextView;

import android.widget.Toast;

import android.widget.AdapterView.OnItemLongClickListener;

public class MainActivity extends Activity {

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
ListView dataListView;
SimpleAdapter listAdapter;
ArrayList<HashMap<String, Object>> list;
private int location;
Handler mHandler = new Handler() { @Override
public void handleMessage(Message msg) {
if (msg.arg1 == 1) { } else if (msg.arg1 == 2) { } else if (msg.arg1 == 4) {
if (msg.what == 1) {
dataListView.getChildAt(msg.arg2).setBackgroundResource(
R.drawable.itemback);
}
}
super.handleMessage(msg);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dataListView = (ListView) findViewById(R.id.lv_list);
list = new ArrayList<HashMap<String, Object>>();
int count = 20;
HashMap<String, Object> map;
for (int i = 1; i <= count; i++) {
map = new HashMap<String, Object>();
map.put("num", i+ "");
map.put("a1", "²=");
map.put("a2", ""+i*i);
list.add(map);
}
listAdapter = new SimpleAdapter(this, list, R.layout.datalist,
new String[] { "num", "a1", "a2" }, new int[] { R.id.tv_num,
R.id.tv_numx, R.id.tv_numy });
dataListView.setAdapter(listAdapter);
dataListView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View view,
int position, long id) {
location = position;
final View nowView = (View) view.findViewById(R.id.ib_edit);
Toast.makeText(getBaseContext(), "location=" + location, 2000)
.show();
OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
Toast.makeText(getBaseContext(), "编辑", Toast.LENGTH_LONG).show();
} else if (which == 1) {
Toast.makeText(getBaseContext(), "删除", Toast.LENGTH_LONG).show();
}
}
};
dataListView.getChildAt(location).setBackgroundResource(
R.drawable.item_frame);
Message message = new Message();
message.arg1 = 4;
message.arg2 = location;
message.what = 1;
mHandler.sendMessageDelayed(message, 500);
String[] Menu = { "编辑", "删除" }; new AlertDialog.Builder(MainActivity.this).setItems(Menu,
listener).show();
return false;
}
});
} public void OnItemEditClick(View v) {
RelativeLayout layout = (RelativeLayout) v.getParent();
TextView tv1=(TextView)layout.findViewById(R.id.tv_num);
TextView tv2=(TextView)layout.findViewById(R.id.tv_numx);
TextView tv3=(TextView)layout.findViewById(R.id.tv_numy);
ImageButton ib=(ImageButton)layout.findViewById(R.id.ib_edit);
String str="按钮"+tv1.getText()+"点击啦n"+tv1.getText()+tv2.getText()+tv3.getText();
Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
}

}

OnItemEditClick(View v)方法中通过v.getParent();找到她的容器控件,前面的(RelativeLayout)根据你自己的布局里的容器控件而定。然后即可使用该容器控件找到他的所有自控件,然后读者想干嘛就干嘛啦~

上面的dataListView.setOnItemLongClickListener实现ListView的item长按事件,我在这里加了一个显示两条菜单的对话框,用于进行其他操作,如编辑、删除等。

这里也可以实现ListView的点击事件,PS:这段代码是后来加的,直接嵌入源代码中即可,已调试无误。

[java] view plaincopyprint?

dataListView.setOnItemClickListener(new OnItemClickListener() {

1
2
3
4
5
6
7
        @Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
TextView tv=(TextView)view.findViewById(R.id.tv_num);
Toast.makeText(getBaseContext(), "您点击了第" + tv.getText()+"行", 2000).show();
}
});

dataListView.setOnItemClickListener(new OnItemClickListener() {

1
2
3
4
5
6
7
        @Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
TextView tv=(TextView)view.findViewById(R.id.tv_num);
Toast.makeText(getBaseContext(), "您点击了第" + tv.getText()+"行", 2000).show();
}
});修改后的MainActivity.java代码如下

[java] view plaincopyprint?

package com.test.customlistview;

import java.util.ArrayList;



import java.util.HashMap;

import android.os.Bundle;



import android.os.Handler;



import android.os.Message;



import android.app.Activity;



import android.app.AlertDialog;



import android.content.DialogInterface;



import android.content.DialogInterface.OnClickListener;



import android.view.View;



import android.widget.AdapterView;



import android.widget.AdapterView.OnItemClickListener;



import android.widget.ImageButton;



import android.widget.ListView;



import android.widget.RelativeLayout;



import android.widget.SimpleAdapter;



import android.widget.TextView;



import android.widget.Toast;



import android.widget.AdapterView.OnItemLongClickListener;

public class MainActivity extends Activity {

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
ListView dataListView;
SimpleAdapter listAdapter;
ArrayList<HashMap<String, Object>> list;
private int location;
Handler mHandler = new Handler() { @Override
public void handleMessage(Message msg) {
if (msg.arg1 == 1) { } else if (msg.arg1 == 2) { } else if (msg.arg1 == 4) {
if (msg.what == 1) {
dataListView.getChildAt(msg.arg2).setBackgroundResource(
R.drawable.itemback);
}
}
super.handleMessage(msg);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dataListView = (ListView) findViewById(R.id.lv_list);
list = new ArrayList<HashMap<String, Object>>();
int count = 20;
HashMap<String, Object> map;
for (int i = 1; i <= count; i++) {
map = new HashMap<String, Object>();
map.put("num", i+ "");
map.put("a1", "²=");
map.put("a2", ""+i*i);
list.add(map);
}
listAdapter = new SimpleAdapter(this, list, R.layout.datalist,
new String[] { "num", "a1", "a2" }, new int[] { R.id.tv_num,
R.id.tv_numx, R.id.tv_numy });
dataListView.setAdapter(listAdapter);
dataListView.setOnItemClickListener(new OnItemClickListener() { @Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
TextView tv=(TextView)view.findViewById(R.id.tv_num);
Toast.makeText(getBaseContext(), "您点击了第" + tv.getText()+"行", 2000).show();
}
});
dataListView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View view,
int position, long id) {
location = position;
final View nowView = (View) view.findViewById(R.id.ib_edit);
Toast.makeText(getBaseContext(), "location=" + location, 2000)
.show();
OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
Toast.makeText(getBaseContext(), "编辑", Toast.LENGTH_LONG).show();
} else if (which == 1) {
Toast.makeText(getBaseContext(), "删除", Toast.LENGTH_LONG).show();
}
}
};
dataListView.getChildAt(location).setBackgroundResource(
R.drawable.item_frame);
Message message = new Message();
message.arg1 = 4;
message.arg2 = location;
message.what = 1;
mHandler.sendMessageDelayed(message, 500);
String[] Menu = { "编辑", "删除" }; new AlertDialog.Builder(MainActivity.this).setItems(Menu,
listener).show();
return false;
}
});
} public void OnItemEditClick(View v) {
RelativeLayout layout = (RelativeLayout) v.getParent();
TextView tv1=(TextView)layout.findViewById(R.id.tv_num);
TextView tv2=(TextView)layout.findViewById(R.id.tv_numx);
TextView tv3=(TextView)layout.findViewById(R.id.tv_numy);
ImageButton ib=(ImageButton)layout.findViewById(R.id.ib_edit);
String str="按钮"+tv1.getText()+"点击啦n"+tv1.getText()+tv2.getText()+tv3.getText();
Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
}

}



package com.test.customlistview;

import java.util.ArrayList;

import java.util.HashMap;

import android.os.Bundle;

import android.os.Handler;

import android.os.Message;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.content.DialogInterface.OnClickListener;

import android.view.View;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.ImageButton;

import android.widget.ListView;

import android.widget.RelativeLayout;

import android.widget.SimpleAdapter;

import android.widget.TextView;

import android.widget.Toast;

import android.widget.AdapterView.OnItemLongClickListener;

public class MainActivity extends Activity {

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
ListView dataListView;
SimpleAdapter listAdapter;
ArrayList<HashMap<String, Object>> list;
private int location;
Handler mHandler = new Handler() { @Override
public void handleMessage(Message msg) {
if (msg.arg1 == 1) { } else if (msg.arg1 == 2) { } else if (msg.arg1 == 4) {
if (msg.what == 1) {
dataListView.getChildAt(msg.arg2).setBackgroundResource(
R.drawable.itemback);
}
}
super.handleMessage(msg);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dataListView = (ListView) findViewById(R.id.lv_list);
list = new ArrayList<HashMap<String, Object>>();
int count = 20;
HashMap<String, Object> map;
for (int i = 1; i <= count; i++) {
map = new HashMap<String, Object>();
map.put("num", i+ "");
map.put("a1", "²=");
map.put("a2", ""+i*i);
list.add(map);
}
listAdapter = new SimpleAdapter(this, list, R.layout.datalist,
new String[] { "num", "a1", "a2" }, new int[] { R.id.tv_num,
R.id.tv_numx, R.id.tv_numy });
dataListView.setAdapter(listAdapter);
dataListView.setOnItemClickListener(new OnItemClickListener() { @Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
TextView tv=(TextView)view.findViewById(R.id.tv_num);
Toast.makeText(getBaseContext(), "您点击了第" + tv.getText()+"行", 2000).show();
}
});
dataListView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View view,
int position, long id) {
location = position;
final View nowView = (View) view.findViewById(R.id.ib_edit);
Toast.makeText(getBaseContext(), "location=" + location, 2000)
.show();
OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
Toast.makeText(getBaseContext(), "编辑", Toast.LENGTH_LONG).show();
} else if (which == 1) {
Toast.makeText(getBaseContext(), "删除", Toast.LENGTH_LONG).show();
}
}
};
dataListView.getChildAt(location).setBackgroundResource(
R.drawable.item_frame);
Message message = new Message();
message.arg1 = 4;
message.arg2 = location;
message.what = 1;
mHandler.sendMessageDelayed(message, 500);
String[] Menu = { "编辑", "删除" }; new AlertDialog.Builder(MainActivity.this).setItems(Menu,
listener).show();
return false;
}
});
} public void OnItemEditClick(View v) {
RelativeLayout layout = (RelativeLayout) v.getParent();
TextView tv1=(TextView)layout.findViewById(R.id.tv_num);
TextView tv2=(TextView)layout.findViewById(R.id.tv_numx);
TextView tv3=(TextView)layout.findViewById(R.id.tv_numy);
ImageButton ib=(ImageButton)layout.findViewById(R.id.ib_edit);
String str="按钮"+tv1.getText()+"点击啦n"+tv1.getText()+tv2.getText()+tv3.getText();
Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
}

}

Android ListView item 点击事件失效问题的解决的更多相关文章

  1. Android ListView中Item点击事件失效解决方案

    欢迎关注公众号,每天推送Android技术文章,二维码如下:(可扫描) 在平常的开发过程中,我们的ListView可能不只是简单的显示下文本或者按钮,更多的是显示复杂的布局,这样的话,我们就得自己写布 ...

  2. 使用PullToRefreshListView时遇到Item点击事件失效问题 解决方法

    最近在自己的项目中使用到了以下开源项目: https://github.com/nanchen2251/pullToRefreshDemo 相关介绍博客如下: http://www.cnblogs.c ...

  3. jquery点击事件失效原因和解决办法

    在使用jQuery绑定点击事件的时候,有时候会遇到点击无效,这种情况大多出现在动态添加元素的时候 例如:给demo里添加li元素给li绑定点击事件 $("#demo").appen ...

  4. ListView item中有button或EditText时 点击事件失效问题的解决

    加入:android:descendantFocusability="blocksDescendants" 代码如下: <LinearLayout xmlns:android ...

  5. ListVIew点击事件失效

    转自:http://blog.csdn.net/zhufuing/article/details/8677407 记录下自己所犯的错误,在写ListView的点击事件时OnItemClickListe ...

  6. ListView点击事件失效(item里面有button按钮控件)解决方法

    ListView点击事件失效解决方法: 一般出现这个情况,就是你的item里面有按钮的点击事件,你的item里面有button控件,button控件是抢占焦点的,只要在你的item布局里面这样子写就可 ...

  7. Android学习---ListView的点击事件,simpleAdapter和arrayadapter,SimpleCursoAdapter的原理和使用

    如题,本文将介绍 listview的点击事件,simpleAdapter和arrayadapter的原理和使用. 1.ListView的注册点击事件 //注册点击事件 personListView.s ...

  8. ListView的item中有button和checkbox,listview的点击事件无效

    ListView的item中有button和checkbox,listview的点击事件无效,解决办法: 在item布局文件中的根控件中添加属性设置: android:descendantFocusa ...

  9. android listview实现点击某个item后使其显示在屏幕顶端

    在该listview的点击事件中加入一下代码即可 listView.setSelectionFromTop(position, 0);

随机推荐

  1. javaweb之Cookie学习

    Cookie简介 HTTP是无状态协议,服务器不能记录浏览器的访问状态,也就是说服务器不能区分中两次请求是否由一个客户端发出.这样的设计严重阻碍的Web程序的设计.如:在我们进行网购时,买了一条裤子, ...

  2. Windows之文件夹中打开PowerShell

    Windows之文件夹中打开PowerShell 为了解决Windows中在某个路径下使用PowerShell,而不是使用传统的cd命令切换过去,具体做法如下: 方法一 打开文件夹 在文件夹的内容区按 ...

  3. Django的contenttypes

    这是一个django内置的表结构,为的就是通过两个字段让表和N张表创建FK关系. 比如说有两种不同课程,这两种课程都有价格周期和策略.如果最低级的则是给每个表创建一个价格策略.如果非要在同一个表内使用 ...

  4. 【转】Word之表格、图片的题注(抬头)自动编号

    问:word中的表格怎么自动插入题注(即表头的编号自动编号)? 答: 1首先搞清楚自动编号的意思.自动插入题注的意思是,在你在word中新建或者复制一个word表格的时候,表头的编号就自动生成了,而不 ...

  5. Python之加密模块

    hashlib模块 加密方式以md5方式加密举例 是标准模块,直接导入即可 还有其他的加密方式,比如:.sha1()..sha224()..sha256()等,加密后的字符串长度更长,安全性更高 一. ...

  6. API接口TOKEN设计

    首先需要知道API是什么?   API(Application Programming Interface)即应用程序接口.你可以认为 API 是一个软件组件或是一个 Web 服务与外界进行的交互的接 ...

  7. jdk下载及环境变量配置

    一.下载 下载链接 二.环境变量:

  8. MyEclipse 10.X激活方法

    普遍的激活办法请参考: http://blog.csdn.net/miss_kun/article/details/51819206 http://jingyan.baidu.com/article/ ...

  9. day 7-20 视图,触发器,事务

    一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...

  10. C# Note23: 如何自定义类型使用foreach循环

    前言 在foreach语句代码中,我们经常是对List,Collection,Dictionary等类型的数据进行操作,不过C#允许用户自定义自己的类型来使用foreach语句.那么自定义类型能够使用 ...