Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash setTextViewTextSize in a widget only without Jelly Bean

I am making a widget in which you can specify the text size

controles.setTextViewTextSize(R.id.LblMsg, TypedValue.COMPLEX_UNIT_SP, textSize);

I am working with android 4.1

android:minSdkVersion="8" android:targetSdkVersion="16"

The problem is that it works correctly in android 4.1, but in any other version (ICS, gingerbread, etc) shows a forced close.

java.lang.NoSuchMethodError: android.widget.RemoteViews.setTextViewTextSize

If I remove the line of code where it is used "setTextViewTextSize", the application works perfectly.

I find no information about the reason for this error.

I appreciate any help.

Regards

like image 718
Sergio76 Avatar asked Aug 28 '12 11:08

Sergio76


3 Answers

if you wish to use something that works on all versions, use this:

remoteViews.setFloat(R.id.textView,"setTextSize",fontSize);
like image 93
android developer Avatar answered Nov 16 '22 15:11

android developer


This method is only available since API level 16 (android 4.1) : http://developer.android.com/reference/android/widget/RemoteViews.html#setTextViewTextSize(int, int, float)

like image 39
sdabet Avatar answered Nov 16 '22 16:11

sdabet


I did this

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
   remoteViews.setTextViewTextSize(R.id.price, TypedValue.COMPLEX_UNIT_PX, 100f);
}
like image 1
Archimedes Trajano Avatar answered Nov 16 '22 16:11

Archimedes Trajano