【问题标题】:Android ListView CheckedTextView BlinkingAndroid ListView CheckedTextView 闪烁
【发布时间】:2010-12-11 18:23:18
【问题描述】:

CheckedTextView 出现问题,我似乎无法找到解决方案。我什至不完全确定发生了什么。

我有一个自定义 ListView,其行包含 TextViews 和 CheckedTextView。

行.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 时没有“闪烁”效果。

对这里发生的事情有任何想法吗?

谢谢

【问题讨论】:

  • 我也有同样的问题。我点击了 CheckedTextView。它被选中,但在一段时间(几毫秒)后它被取消选中。但是,当我用鼠标滚轮滚动(即选择)时,它会保留并传输选择。唔?谢谢
  • 是的,我还没有找到解决方案。如果你这样做,请告诉我。

标签: android android-listview checkedtextview


【解决方案1】:

您应该尝试使用 OnTouchListener,而不是使用 OnClickListener

ckToggle.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                CheckedTextView ck = ((CheckedTextView) v);
                ck.toggle();
                return false;
            }
        });

【讨论】:

    【解决方案2】:

    ListView 在单击项目时使用自己的方案(突出显示背景)。你可能想看看这个解决方案Android how to make View highlight when clicked?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-06
      • 2015-03-18
      • 1970-01-01
      相关资源
      最近更新 更多