0
我已經在我的CustomTweetTimelineListAdapter類中覆蓋了OnClikListener以下示例,並且工作正常,但是當tweet包含url時,未檢測到鏈接點擊並調用適配器OnClicklistener操作,可以如果鏈接被點擊打開url而不是使適配器OnClickListener操作?點擊自定義適配器上的鏈接
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);
}
}
}
}
你有沒有簽出[這](http://stackoverflow.com/questions/11007008/whats-the-best-way-to-check-if-a-string-contains-a-url-in-java - 機器人)的答案?也許在返回的字符串中「監聽/檢查」url? –
或者在TextView中使用'android:autoLink' –