Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView BufferType

From the android docs, there are 3 types of buffer for TextView, EDITABLE, NORMAL and SPANNABLE. What is the difference between each of them and what are some of their common use cases?

like image 673
Gerald Avatar asked Oct 31 '16 18:10

Gerald


People also ask

What is TextView BufferType?

TextView. BufferType will be used for changing the TextView in runtime like insert, setting the different color in a single TextView, style etc. EDITABLE -> only return Spannable and Editable.

What is BufferType?

android.widget.TextView.BufferType. Type of the text buffer that defines the characteristics of the text such as static, styleable, or editable.


1 Answers

TextView.BufferType will be used for changing the TextView in runtime like insert, setting the different color in a single TextView, style etc.

EDITABLE -> only return Spannable and Editable.

NORMAL ->only return any CharSequence.

SPANNABLE -> only return Spannable.

Here is TextView.BufferType.EDITABLE uses.

yourTextView.setText("is a textView of Editable BufferType",TextView.BufferType.EDITABLE);
/* here i insert the textView value in a runtime*/
Editable editable = youTextView.getEditableText();
editable.insert(0,"This ");  //0 is the index value where the "TEXT" will be placed

Ouput:

This is a textView of Editable BufferType

Here is TextView.BufferType.SPANNABLE uses and This is also written by TextView.BufferType.EDITABLE (because editable written spannable or editable) by changing the arguments

yourTextView.setText("textView of Spannable BufferType",TextView.BufferType.SPANNABLE);
/* here i change the color in a textview*/
Spannable span = (Spannable)yourTextView.getText();
span.setSpan(new ForegroundColorSpan(0xff0000ff),11,"textView of Spannable BufferType".length(),Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

Output:

textView of  `Spannable BufferType`(Spannable BufferType are in blue color)
like image 181
Rao Arsalan Avatar answered Sep 21 '22 16:09

Rao Arsalan