Karthik Kolanji Karthik Kolanji - 5 months ago 75
Android Question

compulsory asterisk in textview android

I using the fields which are mandatory , for this I am using

textview
which includesred colored asterisk

My output: click link!

Required output : click link!

I tried to modify the code,but didn't got expected result

public void setCompulsoryAsterisk(){

txt_name="Name : ";
String colored="*";
SpannableStringBuilder strBuilder=new SpannableStringBuilder();
strBuilder.append(txt_name);
int start=strBuilder.length();
strBuilder.append(colored);
int end=strBuilder.length();
strBuilder.setSpan(new ForegroundColorSpan(Color.RED), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
txtName.setText(strBuilder);
}

Answer
String txt_name="Name ";
String colored="*";
String colon = " : ";

after you append string colored, append string colon after it. Voila.

Comments