Android - отображение гиперссылок - PullRequest
0 голосов
/ 01 апреля 2012

Я получаю сообщение от PHP-скрипта. И я загружаю это в textview в приложении для Android. Это сейчас показывается как текст. Как я могу отобразить его как гиперссылку, чтобы щелкнуть по нему, чтобы перейти к электронной почте?

package com.example.login2;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;


public class SAppointmentActivity extends Activity {
    TextView news;

    @Override
    protected void onCreate(Bundle savedInstanceState1) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState1);
        setContentView(R.layout.snews);
        news = (TextView)findViewById(R.id.news);
        news.setText("Hello");

        ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
        MyApp MyAppVar = new MyApp();
        postParameters.add(new BasicNameValuePair("username", MyAppVar.getName()));
        postParameters.add(new BasicNameValuePair("password", MyAppVar.getPasswd()));

        //String valid = "1";
        String response = null;
        try {
            response = CustomHttpClient.executeHttpPost("http://192.168.1.8/appointment.php", postParameters);
            String res=response.toString();
            // res = res.trim();
            //res= res.replaceAll("\\s+","");
            news.setText(res);
        }
        catch (Exception e) {
            news.setText("Error");
        }
    }
}

Ответы [ 2 ]

1 голос
/ 01 апреля 2012
Linkify.addLinks(news, Linkify.EMAIL_ADDRESSES);
1 голос
/ 01 апреля 2012
TextView email = (TextView)findViewById(R.id.TextView04);
email.setText("sadasd asmn@gmail.com");
email.setLinkTextColor(Color.WHITE);
Linkify.addLinks(email,Linkify.EMAIL_ADDRESSES);

Это рабочий код. Просто попробуйте.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...