1

I wrote application which uses ListActivity. Each item of the list consists of ImageView and TextView. Long click on list entry triggers some menu and color effect because onCreateContextMenu was overridden. Sometimes TextView contains HTML links which I would like to be interactive. I read #1697908 and made links active, so browser/youtube player is started. Everything would be great but color effect on long click disappeared (context menu still appears).

Could somebody tell me how to connect these two features and get back color effect?

2
  • possible duplicate of ListView items won't show focus when touched Commented Jun 23, 2010 at 20:37
  • I don't think so because problem presented by you is caused by row clickable property which is set to true. Here everything was working till HTML links handling was added. Commented Jun 23, 2010 at 20:57

3 Answers 3

1

You can use Linkify in a custom list adapter. Linkify allows you to set colors using a selector like so:

                Linkify.addLinks(
                        holder.messageText,
                        messageDetailsMatcher,
                        "content://com.myApp/message/view?messageId=",
                        null, new myLinkTransformFilter(msgId));


                ColorStateList colors = null;
                try {
                    XmlResourceParser xpp = getResources().getXml(
                            R.color.link_color_selector);
                    colors = ColorStateList.createFromXml(getResources(),
                            xpp);
                } catch (Exception e) {
                    Log.e("someError", e);
                }
                holder.messageText.setLinkTextColor(colors);

(note: the holder.messageText is a simple TextView in a holder object)

then you have a /res/color/color_selector.xml like this:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:color="@drawable/message_focused" /> <item android:state_pressed="true" android:state_enabled="false" android:color="@drawable/message_pressed" /> <item android:state_enabled="false" android:color="@drawable/message_enabled" /> <item android:state_active="true" android:color="@drawable/message_active" /> <item android:color="@drawable/message_default" /> </selector>

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. I am trying to add Linkify in a custom list adapter all the time. I'm not quite sure whether it solves my problem. How color state applied to single TextView could return change of color effect on entire row (LinearLayout which contains TextView).
0

I used a ImageView and a Textview at the beginnin, but you can avoid that kind of problems using a WebView and keep the html interactivity.

read this

How can I have a floating image (right aligned) with text that wraps around the image in Android Layout?

Comments

0

I've managed to solve this issue. Maybe not directly in such a way I wanted but it's enough for me. Instead of adding listener to TextView I add it to entire row. Highlighting is working as I expected. This behaviour is acceptable for my app but is some kind of workaround so I still would like to know whether it can be done better.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.