• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Any easier way than new TextView(this) ?

I just started looking at the tutorial here:
http://developer.android.com/training/basics/firstapp/starting-activity.html

For this class
Code:
public class DisplayMessageActivity extends ActionBarActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  // Get the message from the intent
  Intent intent = getIntent();
  String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
  // Create the text view
  TextView textView = new TextView(this);
  textView.setTextSize(40);
  textView.setText(message);
  // add the TextView as the root view of the activity’s layout by passing it to setContentView()
  setContentView(textView);
  }
...

Is there an easier way than the multiple lines of code to get the string displayed? Why isn't the textView a member of the class? It feels like a member but I guess it's not for whatever reason, so we end up with the convoluted way
Code:
TextView textView = new TextView(this);
to get to it.

Any help with understanding the philosophy behind this will be highly appreciated. Thanks!
 
Back
Top Bottom