对CheckEdTextView有一个问题,我似乎找不到解决方案。我什至不确定发生了什么。

我有一个自定义列表视图,其行包含textViews和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时,白色文本要么消失或切换黑色(可能是反转?),当您释放时,文本重新出现和Checkmark切换。按下ListView时,没有“闪烁”效果。

关于这里发生的事情有什么想法吗?

谢谢

有帮助吗?

解决方案

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

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

其他提示

单击项目时,ListView使用自己的方案(突出显示背景)。您可能想检查一下此解决方案 单击时如何使视图突出显示?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top