Reputation: 1424
Is their anyway to display static and dynamic data in textview..
here is my textview defining in my xml
<TextView
android:gravity="center_horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:id="@+id/Rowtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:text="Listiems" />.
i have to display the text which is their in android:text and the dynamic data next to it.
is their any way?
Thanks:)
Upvotes: 0
Views: 3162
Reputation: 133580
<TextView
android:gravity="center_horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:id="@+id/Rowtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:text="Listiems" />.
TextView _tv= (TextView) findViewById(R.id.Rowtext);
StyleSpan boldSpan = new StyleSpan( Typeface.BOLD );
SpannableString ss= new SpannableString("Your Dynamic text");
ss.setSpan( boldSpan, 0, ss.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE );
_tv.append(" ");
_tv.append(ss);
For styling spannable string. http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring
Resulting snapshot
Upvotes: 1
Reputation: 56935
Use
String tempString="Your Dynamic text Here";
TextView text=(TextView)findViewById(R.id.Rowtext);
SpannableString spanString = new SpannableString(tempString);
spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, spanString.length(), 0);
text.setText(" ");
text.append(spanString);
Upvotes: 1
Reputation: 6112
There are two ways to do that 1) Provide static text in android:text parameter and then append dynamic text from you class
android:text="some static String"
textView.append(Some dynamic String");
2) OR you can gave both in class file like below
textView.setText(getString(R.string.someString)+"Some dynamic String");
Upvotes: 1