我收到一封来自PHP脚本的电子邮件。我正在将它加载到Android应用程序的textview中。它现在被显示为文本。如何将其显示为超链接,以便我可以单击它以转到电子邮件?
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");
}
}
}
答案 0 :(得分:1)
TextView email = (TextView)findViewById(R.id.TextView04);
email.setText("sadasd asmn@gmail.com");
email.setLinkTextColor(Color.WHITE);
Linkify.addLinks(email,Linkify.EMAIL_ADDRESSES);
这是工作代码。试试吧。
答案 1 :(得分:1)
Linkify.addLinks(news, Linkify.EMAIL_ADDRESSES);