0

I created a listview wit custom addapter to display tweets from a user. Now sometimes in the tweet there is a link provided. I want them to be clickable, and the item itself from the listview doesn't have to be clickable. this is the layout of my listview with 2 rows to show an example

IMG

I have tried to make the links in the textview(text with sometimes links) clickable and also autolink: WEB in XML and programatically. But every time i click on the link it selects the listitem en not the link in the textview.

In java code it was like this :

message.setAutoLinkMask(1); message.setLinksClickable(true);

public class UserItemAdapter extends ArrayAdapter<Tweet> {
    private ArrayList<Tweet> tweets;

    public UserItemAdapter(Context context, int textViewResourceId,
            ArrayList<Tweet> tweets) {
        super(context, textViewResourceId, tweets);
        this.tweets = tweets; 
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.listitem, null);
        }

        Tweet tweet = tweets.get(position);
        if (tweet != null) {
            TextView username = (TextView) v.findViewById(R.id.username);
            TextView message = (TextView) v.findViewById(R.id.message);
            **message.setAutoLinkMask(1);
            message.setLinksClickable(true);**
            ImageView image = (ImageView) v.findViewById(R.id.avatar);
            TextView date = (TextView) v.findViewById(R.id.date);
            if (username != null) {
                username.setText(tweet.username);
            }

            if (message != null) {
                message.setText(tweet.message);
            }

            if (date != null) {
                date.setText(tweet.hfdate);
            }
        }
        return v;
    }
}

and the xml for the listitem is like this in the textview message like this

android:autoLink="web" android:linksClickable="true"

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center"
android:paddingBottom="5px"
android:paddingLeft="5px"
android:paddingTop="5px"
tools:context=".TwitterActivity$AsyncOp" >

<ImageView
    android:id="@+id/avatar"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_marginRight="6dip"
    android:src="@drawable/twitterimg" />

<LinearLayout
    android:layout_width="0dip"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="@color/Orange" />

    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10px"
        android:autoLink="web"
        android:linksClickable="true"
        android:textColor="#0099CC" />

    <TextView
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10px"
        android:textColor="@color/Orange" />
</LinearLayout>

</LinearLayout>

Anybody an idea wath I am doing wrong?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
pieter
  • 385
  • 1
  • 4
  • 19

0 Answers0