views:

33

answers:

1

I wanna make an app which is quite similar to the official twitter client for android.

In my listView Item ,there is a TextView which has some html content,I hope the links within it can be focusable and clickable,I have used:

getListView().setItemsCanFocus(true);

but it still doesn't work,I don't know why.

the layout is like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item"
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content"
 android:orientation="horizontal" 
 android:padding="6dip"
 android:background="#FFFFFF">
 <ImageView android:id="@+id/avatar" 
     android:layout_width="wrap_content"
  android:layout_height="fill_parent" 
  android:layout_marginRight="6dip"
  android:src="@drawable/default_happy_face" />
 <LinearLayout 
     android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
  <RelativeLayout
      android:id="@+id/linearBanner"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="20dip">
   <TextView android:id="@+id/txtNickname" 
       android:layout_width="wrap_content"
    android:textColor="#1C86EE"
    android:text="mmLiu" android:layout_height="fill_parent"/>
   <ImageView android:id="@+id/verified" 
             android:layout_width="24dip"
          android:layout_height="24dip"
          android:paddingLeft="4dip"
          android:layout_toRightOf="@id/txtNickname"
          android:background="@drawable/verified"/>
      <TextView android:id="@+id/txtTime" 
       android:textColor="#999999" 
       android:layout_height="fill_parent" 
       android:layout_alignTop="@+id/txtNickname" 
       android:layout_alignRight="@layout/notice_item" android:layout_toRightOf="@+id/verified" android:layout_width="fill_parent" android:gravity="right" android:text="半个小时前"/>
  </RelativeLayout>
  <TextView android:id="@+id/txtContent" 
      android:layout_width="fill_parent"
   android:layout_height="wrap_content" 
   android:textColor="#050505"
   android:text="!时尚起义 波点连衣裙原价116,现价69素雅波点拼接长裙,素色上装搭配雪纺波点短裙,优雅恬静,非你莫属!【商家地址:http://1net.cn/8wf】#服饰#" android:clickable="true"/>
 </LinearLayout>
</LinearLayout>

I hope the links can be focused instead of the whole item,this issue have been discussed in the google io,see here and the solution is getListView().setItemsCanFocus(true); But it just doesn't work for me.

I used an comstimized adapter which extends the BaseAdapter,I don't know if that has sth to do with it.

anyone? any help ?

A: 

Found the solution by myself:

if you want the link in TextView clickable,you should add one more line:

yourTextView.setMovementMethod(LinkMovementMethod.getInstance());

besides

getListView().setItemsCanFocus(true);

That's all.

see the link: here

DiveInto