setTextSize using data in string-array



I'm trying to set the size of TextView which is textView1 using data from preferences activity which using ListPreference and have three options. Here is the ListPreference, prefs.xml in res.xml folder :



<ListPreference
android:title="Text Size"
android:key="textsize"
android:summary="Let you choose text size"
android:entries="@array/textsize"
android:entryValues="@array/textSize" />


here is the array.xml in res.values folder



<string-array name="textsize" >
<item >Small</item>
<item >Medium</item>
<item >Large</item>
</string-array>

<string-array name="textSize" >
<item name="android:textSize">14sp</item>
<item name="android:textSize">18sp</item>
<item name="android:textSize">22sp</item>
</string-array>


Is there any way to set the size directly into xml file? This case is main.xml



<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/long_string"
android:textSize="" />


or into the class? I know the code below is wrong. It does not do anything. I'm sorry, just started programming in android.



TextView tV=(TextView) findViewById(R.id.textView1);
tV.setText(R.array.textSize);

No comments:

Post a Comment