Question

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

Was it helpful?

Solution

Instead of using OnClickListener you should try using OnTouchListener

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

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top