Trying to get started with Android development and do basic work with TextViews.
For some reason, the TextView setText () method is causing huge problems for me .. here is a simplified version of my code to show what I mean:
package com.example.testapp; import android.os.Bundle; import android.app.Activity; import android.widget.TextView; public class MainActivity extends Activity { TextView text; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); text = (TextView) findViewById(R.id.text1); setContentView(R.layout.activity_main); text.setText("literally anything"); } }
This will fail, and I don’t understand why .. if I create a TextView inside onCreate, it works fine, but if I create it outside it is not .. why? Has the string "TextView text"; not done yet or something else?
Thanks!
android string textview settext
Zeldarulah
source share