0

I have overwritten the OnClikListener on my CustomTweetTimelineListAdapter class following and example and works fine but when the tweet contains a url the click on the link is not detected and make call the adapter OnClicklistener action, it's possible to make if the link is clicked open the url instead of make the adapter OnClickListener action?

package client.tclient.com.client;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;

import com.twitter.sdk.android.core.models.Tweet;
import com.twitter.sdk.android.tweetui.Timeline;
import com.twitter.sdk.android.tweetui.TweetTimelineListAdapter;

/**
 * Created by alvaro on 13/06/16.
 */
public class CustomTweetTimelineListAdapter extends TweetTimelineListAdapter implements Adapter{

    private Context context;
    /**
     * Constructs a TweetTimelineListAdapter for the given Tweet Timeline.
     *
     * @param context  the context for row views.
     * @param timeline a Timeline<Tweet> providing access to Tweet data items.
     * @throws IllegalArgumentException if timeline is null
     */
    public CustomTweetTimelineListAdapter(Context context, Timeline<Tweet> timeline) {
        super(context, timeline);
        this.context = context;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = super.getView(position, convertView, parent);

        //disable subviews
        if(view instanceof ViewGroup){
            disableViewAndSubViews((ViewGroup) view);
        }

        //enable root view and attach custom listener
        view.setEnabled(true);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Long tweetId = getItemId(position);
                Intent intent = new Intent(context,TweetActivity.class);
                intent.putExtra("TWEET_ID", tweetId);
                context.startActivity(intent);
            }
        });
        return view;
    }
    private void disableViewAndSubViews(ViewGroup layout) {
        layout.setEnabled(false);
        for (int i = 0; i < layout.getChildCount(); i++) {
            View child = layout.getChildAt(i);
            if (child instanceof ViewGroup) {
                disableViewAndSubViews((ViewGroup) child);
            } else {
                child.setEnabled(false);
                child.setClickable(false);
                child.setLongClickable(false);
            }
        }
    }
}
AFS
  • 1,433
  • 6
  • 28
  • 52
  • Have you checked out [this](http://stackoverflow.com/questions/11007008/whats-the-best-way-to-check-if-a-string-contains-a-url-in-java-android) answer? Maybe "listen/check" for url within the returned string? – Steve C. Jun 19 '16 at 13:03
  • Or make use of `android:autoLink` in the TextView – Steve C. Jun 19 '16 at 13:05

1 Answers1

0

Your view should contain a reference for the link lets suppose it's TextView and define a listener for that subview.

tamtom
  • 2,474
  • 1
  • 20
  • 33