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?

Community
  • 1
  • 1
boro
  • 205
  • 5
  • 8
  • possible duplicate of [ListView items won't show focus when touched](http://stackoverflow.com/questions/3078323/listview-items-wont-show-focus-when-touched) – Pentium10 Jun 23 '10 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. – boro Jun 23 '10 at 20:57

3 Answers3

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>

Ben
  • 16,124
  • 22
  • 77
  • 122
  • 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). – boro Jun 24 '10 at 06:03
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?

Community
  • 1
  • 1
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
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.

boro
  • 205
  • 5
  • 8