E
Ernesto S
Neues Mitglied
- 0
Hallo,
wie in zahlreichen Tutorials beschrieben, ist es sehr einfach, den Text eines TextViews in onCreate nach setContentView zu ändern.
Leider führt das bei mir so nicht zum Erfolg.
LogCat zeigt keinen Fehler, aber textView ist null.
Vielen Dank für die Hilfe Ernesto
Hier Coding, Layout und Manifest:
wie in zahlreichen Tutorials beschrieben, ist es sehr einfach, den Text eines TextViews in onCreate nach setContentView zu ändern.
Leider führt das bei mir so nicht zum Erfolg.
LogCat zeigt keinen Fehler, aber textView ist null.
Vielen Dank für die Hilfe Ernesto
Hier Coding, Layout und Manifest:
Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
TextView textView = (TextView)this.findViewById(R.id.textView1);
if (textView != null){
Log.d("TEST", "Alles io");
String str = "na geht doch !";
textView.setText(str);
} else {
Log.d("TEST", " textView ist null");
}
}
Code:
<LinearLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="horizontal"
tools:context="com.example.mytest.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mytest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mytest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>