Question

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?

Was it helpful?

Solution 3

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.

OTHER TIPS

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>

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?

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