Posts

Showing posts from March, 2014

Bullets List in Android?

  A much needed, sometimes hidden in the framework, and mimicked with unnecessary WebViews and sort of inner HTML injections to xml resources – a bullet list is much easier to implement then you would expect. When taking the easy solution – using WebViews , you are making the UI hierarchy much heavier then it should be, and when your UI is already rich with layouts and widgets, it seems bad to overload it with heavy WebViews. The Android.text framework gives us – the developers an easy to use API to build special text spans, in the next code snippet we’ll see how a bullet list can be implemented: let’s say we have a simple TextView which we need to hold a text with a bullet at the left hand of it: TextView mTv = (TextView)findViewById(R.id.tv_1); CharSequence cs = getText(R.String.sample_text); SpannableString ss = new SpannableString(cs); ss.setSpan(new BulletSpan(15), 0, cs.length(), 0); mTv.setText(ss);   Explanation: 1. Get a hook on a TextView 2. Construct a CharSeq