int resID = getResources().getIdentifier(getResources().getString(R.string.hello_world), "id", "com.example.test.projects");
TextView text = (TextView)findViewById(resID);
text.setText("cpu: " );
I cant seem to change the hello_world message … it throws errors every time
Originally it was a lot more strait forward looking but :/ i noticed in my R file that my string for hello world didnt seem to have a ID like in many of the examples of changing the text view so i threw this together
heres where i made the layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".MainActivity" />
and my main xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test.projects"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<uses-feature android:name="android.hardware.bluetooth"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I suggest a different approach, add an id to your TextView:
And you can change its text with:
(Also if your app crashes, you should always post your LogCat so we can see exactly what is happening.)