If you search on the internet about how to show a bulleted list from strings.xml using HTML tags, most of the answers will say that you should use a WebView, or to use the bullet symbol directly, or other alternatives. And on some posts I even read that you can’t use <li> tag from HTML because it is not recognized in Android. This is totally untrue. Here, in this post you can see all the HTML tags which are supported and which are NOT supported. I tried them all 🙂
Below I will show you how I used <li> tag in order to show a bulleted list from strings.xml.
<resources> <string name="bullted_list"><b><big>Bulleted List</big></b> \n <li>Item one</li> \n <li>Item two</li> \n <li>Item three</li> </string> </resources>
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="ro.tutorial.funcode.backstack.A"> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="15dp" /> </android.support.constraint.ConstraintLayout>
TextView textView = findViewById(R.id.text); textView.setText(R.string.bullted_list);
And below is the result 🙂
As you can see, is pretty easy to show a bulleted list if you need to show it on a TextView. So there’s no need to refactor your code to use WebView or other alternatives. Of course, if you don’t like this approach, you can use the others. I don’t want to imply this the correct and only way to show bullets. But I wanted to write this post, because I didn’t find this approach anywhere else and maybe someone will need it, or like it more than the other ones :P.
Please let me know if you find this post useful by writing a comment or rating it. Also don’t forget to share it if you liked it 😉