我使用列表视图和Firebase进行了Android聊天。我想在聊天消息中激活链接。链接在message_text textview的文本中采用不同的格式。我怎么能活跃他们?
我的代码:
item_in_message.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bubble_in">
<TextView
android:id="@+id/message_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="fdsfsdf"
android:textStyle="normal|bold" />
<TextView
android:id="@+id/message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/message_user"
android:layout_marginTop="5dp"
android:text="dsfsdfds"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@android:color/white"
android:textSize="18sp" />
<TextView
android:id="@+id/message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/message_text"
android:text="sdfsdfsd" />
item_out_message.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/bubble_out">
<TextView
android:id="@+id/message_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="fdsfsdf"
android:textStyle="normal|bold" />
<TextView
android:id="@+id/message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/message_user"
android:textColor="@android:color/white"
android:layout_marginTop="5dp"
android:text="dsfsdfds"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="18sp" />
<TextView
android:id="@+id/message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/message_text"
android:text="sdfsdfsd" />
</RelativeLayout>
答案 0 :(得分:1)
将xml中的这些行添加到textview标记
android:autoLink="web"
android:linksClickable="true"
答案 1 :(得分:0)
您需要制作列表视图基本适配器实现
例如
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public boolean onItemClick(AdapterView<?> parent, View view, int position, long id) {
//here you can use the position to determine what checkbox to check
//this assumes that you have an array of your checkboxes as well. called checkbox
checkBox[position].setChecked(!checkBox.isChecked());
}
});
ListView是您的列表适配器 List adapter reference