I am writing an app for android and i am trying to have part of the string hyperlinked to another page within the app, but am struggling as to how to do it.
I have managed to get it to work with a whole textview like this:
TextView txtVirus = (TextView) findViewById(R.glossaryMalwareID.txtVirus);
txtVirus.setText(Html.fromHtml("<U>Computer Virus<U>"));
txtVirus.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent ("com.digitalsecurity.app.GLOSSARYVIRUS"));
}
});
however this means that the string has to be on a compleatly new line (or so i believe).
What i would like is to be able to do as the notes in the code below show:
TextView txtVirus = (TextView) findViewById(R.glossaryMalwareID.virusmain);
txtVirus.setText(Html.fromHtml("<br>" +
"A Computer Virus is a small peice of " +
"Software" +//i want the word 'software' hyperlinked to another page in my program
"so on and so on"));
after 4 hours of searching and tweaking i have the answer:
i got the help from here which also has other rather helpfull formatting options:
http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring
i hope it helps someone else who needs the same