Android ListView CheckedTextView 闪烁
CheckedTextView 有问题,我似乎找不到解决方案。我什至不完全确定发生了什么。
我有一个自定义 ListView,其行包含 TextView 和 CheckedTextView。
row.xml
<CheckedTextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/title"
android:text="Name"
android:gravity="center_vertical"
android:paddingRight="6dip"
android:typeface="sans"
android:checkMark="?android:attr/textCheckMark"
android:textSize="16sp"
android:textStyle="bold"/>
MyAdapterView.java
public class RuleAdapterView extends LinearLayout
{
private CheckedTextView title;
...
title = (CheckedTextView)v.findViewById(R.id.title);
title.setText(entry.getName());
title.setChecked(entry.isActive());
// setup a listener for the checkbox
title.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
((CheckedTextView) v).toggle();
}
});
}
在主 XML 文件中,我将 ListView 设置为 android:choiceMode="multipleChoice"
。
所以我想要的是 ListView 行是长的和短的可点击,并且 CheckedTextView 是单独的点击执行。这适用于 CheckedTextView 的文本部分。每当按下 CheckedTextView 时,文本就会“闪烁”。我慢慢地弄清楚到底发生了什么。当您按下 CheckTextView 时,白色文本会消失或切换为黑色(可能反转?),当您松开时,文本会重新出现并且复选标记会切换。按下 ListView 时不会出现“闪烁”效果。
对这里发生的事情有什么想法吗?
谢谢
Having an issue with CheckedTextView that I can't seem to find a solution. I'm not even entirely sure what's happening.
I have a custom ListView whose rows contain TextViews and a CheckedTextView.
row.xml
<CheckedTextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/title"
android:text="Name"
android:gravity="center_vertical"
android:paddingRight="6dip"
android:typeface="sans"
android:checkMark="?android:attr/textCheckMark"
android:textSize="16sp"
android:textStyle="bold"/>
MyAdapterView.java
public class RuleAdapterView extends LinearLayout
{
private CheckedTextView title;
...
title = (CheckedTextView)v.findViewById(R.id.title);
title.setText(entry.getName());
title.setChecked(entry.isActive());
// setup a listener for the checkbox
title.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
((CheckedTextView) v).toggle();
}
});
}
And in the main XML file I set the ListView to android:choiceMode="multipleChoice"
.
So what I want is for the ListView rows to be long and short clickable and for the CheckedTextView to be separate click execution. This works with the exception of the text part of the CheckedTextView. Whenever either the CheckedTextView is pressed, the text 'flickers'. I did it slowly to figure out exactly what was going on. When you press down on the CheckTextView, the white text either disappears or toggles black (possibly inverts?) and when you release, the text reappears and the checkmark toggles. There is no 'flicker' effect when the ListView is pressed.
Any ideas on what's going on here?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该尝试使用 OnTouchListener 而不是使用 OnClickListener
Instead of using OnClickListener you should try using OnTouchListener
单击某个项目时,ListView 使用自己的方案(突出显示背景)。您可能想查看此解决方案 Android 如何制作单击时查看突出显示?
ListView uses its own scheme when an item is clicked (highlighting the background). You might want to check out this solution Android how to make View highlight when clicked?