2017-01-28 3 views
0

Ich habe einen Android-Chat mit der Verwendung von Listenansicht und Firebase gemacht. Ich möchte Links in Chat-Nachrichten aktiv machen. Links sind im Text von message_text textview in verschiedenen Formaten. Wie kann ich sie aktiv machen?Klickbare URL in Listenansicht

Mein Code:

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

Welche Art von 'Links/url' Sie machen bedeuten? Netz? Browser-App sollte geöffnet sein? – eleven

+0

@eleven Einfache URL-Links (z. B. www.google.com, http: // google.com) –

Antwort

1

diese Zeilen in XML zu dem textvie hinzufügen w-Tag

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

Sie benötigen eine Listenansicht Basis Adapter Implementierung

zum Beispiel

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 ist die Liste Adapter List adapter reference