2012-04-01 89 views
-1

我收到一封来自PHP脚本的电子邮件。我将它加载到Android应用程序的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"); 
     } 
    } 
} 

回答

1
TextView email = (TextView)findViewById(R.id.TextView04); 
email.setText("sadasd [email protected]"); 
email.setLinkTextColor(Color.WHITE); 
Linkify.addLinks(email,Linkify.EMAIL_ADDRESSES); 

这是工作的代码。去尝试一下。

1
Linkify.addLinks(news, Linkify.EMAIL_ADDRESSES);