In the last post, I showed you guys how to show HTML inside the TextView.
But the thing was that if you had links in your HTML then they wouldn’t work. That is the links would show like they should but if you clicked on the links nothing would happen.
That is because they aren’t enabled yet.
You can enable the links inside the HTML or the TextView for that matter by just adding a couple of lines of code.
Just make sure that you are passing the text to the TextView from a string resource. And then add the following code to the OnCreate Method of your JAVA file of the Activity:
TextView newtext = (TextView) findViewById(R.id.textView1); newtext.setMovementMethod(LinkMovementMethod.getInstance());
So that the JAVA file looks like this:
That’s it! That’s how you enable the links inside the TextView.
Hope you found it useful.
Leave your questions in the Comments Section below.
Ph.D. researcher at Friedrich-Schiller University Jena, Germany. I’m a physicist specializing in computational material science. I write efficient codes for simulating light-matter interactions at atomic scales. I like to develop Physics, DFT, and Machine Learning related apps and software from time to time. Can code in most of the popular languages. I like to share my knowledge in Physics and applications using this Blog and a YouTube channel.