Different size of strings in the same TextView

I have a textView inside with a number (variable) and a string, how can I give the number one size larger than the string? the code:

    TextView size = (TextView)convertView.findViewById(R.id.privarea_list_size);
    if (ls.numProducts != null) {
        size.setText(ls.numProducts + " " + mContext.getString(R.string.products));


I want ls.numproducts has a size different from the rest of the text. how to do?


Use a Spannable String

 String s= "Hello Everyone";
 SpannableString ss1=  new SpannableString(s);
 ss1.setSpan(new RelativeSizeSpan(2f), 0,5, 0); // set size
 ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);// set color
 TextView tv= (TextView) findViewById(R.id.textview);

Snap shot

You can split string using space and add span to the string you require.

 String[] each;
 String s= "Hello Everyone";  
 for(int i=0;i<s.length();i++)
     each = s.split("\\s");         

Now apply span to the string and add the same to textview.

Need Your Help

AT91SAM7X512 reset type issue

embedded arm microcontroller reset atmel

I am using an AT91SAM7X512 for my application. I perform a software reset after certain action. The processor resets. But upon reading the RSTC_RSR status register I get an invalid register value f...

How to limit certain behavior to a subset of instances of a particular class?

c# domain-driven-design data-modeling

I'm working on the domain model for a recipe application and running into an issue.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.