problem in bold text

Put your problem here if it does not fit any of the other categories.

problem in bold text

Postby rmeph » Fri Feb 15, 2008 9:40 am

i have
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String s1="<b>boldtext</b>" ;
  2.  
  3.    CharSequence str=s;
  4.  
  5.    TextView textview=(TextView)findViewById(R.id.text);
  6.  
  7.    textview.setText(str);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


and textview in xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <TextView id="@+id/text"
  2.  
  3. android:autoLink="all"
  4.  
  5.   android:layout_width="fill_parent"
  6.  
  7.   android:layout_height="fill_parent"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


but it not show in bold text .......
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Top

Postby Jesmiatka » Fri Feb 15, 2008 9:53 am

Hi,

are you using the new SDK?
If so change the following in your XML:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <TextView id="@+id/text"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


to

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <TextView android:id="@+id/text"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Also, those HTML syntaxes are only usable when you are making a reference to a String value in resources.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <resource>
  3.  
  4.     <string name="bold">This is a <b>bold</b>word</string>
  5.  
  6. </resources>
  7.  
  8.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


more information on: http://code.google.com/android/kb/commo ... ectingtext
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Postby rmeph » Fri Feb 15, 2008 12:24 pm

not i used m3-rc37a sdk.....i cannot used string value as resource actullay string value decide at runtime...any other idea for that...............
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby plusminus » Fri Feb 15, 2008 12:38 pm

Hello rmeph,

1. You should upgrade to m5

2. To style text on the fly, you must make sure the TextView is using Spannable storage for the text (this will always be true if the TextView is an EditText), retrieve its text with getText(), and call setSpan(Object, int, int, int), passing in a new style class from the android.text.style package and the selection range.

The following code snippet demonstrates creating a string with a highlighted section, italic section, and bold section, and adding it to an EditText object.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. // Get our EditText object.
  2.  
  3. EditText vw = (EditText)findViewById(R.id.text);
  4.  
  5.  
  6.  
  7. // Set the EditText's text.
  8.  
  9. vw.setText("Italic, highlighted, bold.");
  10.  
  11.  
  12.  
  13. // If this were just a TextView, we could do:
  14.  
  15. // vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE);
  16.  
  17. // to force it to use Spannable storage so styles can be attached.
  18.  
  19. // Or we could specify that in the XML.
  20.  
  21.  
  22.  
  23. // Get the EditText's internal text storage
  24.  
  25. Spannable str = vw.getText();
  26.  
  27.  
  28.  
  29. // Create our span sections, and assign a format to each.
  30.  
  31. str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  32.  
  33. str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  34.  
  35. str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby rmeph » Fri Feb 15, 2008 1:21 pm

thanks for reply....i try it....In m5, i cannot find extras.putStringArray() that why i m used m3 sdk
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby Jesmiatka » Fri Feb 15, 2008 1:23 pm

Hi,

you should be using the latest version anyway, since phone's are gonna be using the latest versions.
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Top

Postby plusminus » Fri Feb 15, 2008 1:36 pm

Hello rmeph,

you could create a small parcelable -Wrapper
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         class MyPseudoArray implements Parcelable{
  2.                 private String[] strs;
  3.                 MyPseudoArray(String[] aStrArr){ this.strs = aStrArr;}
  4.                 @Override
  5.                 public void writeToParcel(Parcel pParcel) {
  6.                   pParcel.writeStringArray(strs);
  7.                 }
  8.         }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

Then use it like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Bundle b = new Bundle();
  2. b.putParcelable("bla", new MyPseudoArray(new String[]{"A","B","C"}));
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


(untested)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby rmeph » Fri Feb 15, 2008 3:09 pm

thanks....i will try....if i want new line after particular index....then what is use for that?
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests