This is a confusing question. But if you want the string variable to be the string from your xml file you should do the following:
String message = this.getResources().getString(R.string.entered_message);
However the way you're doing things here seems very strange. But without knowing exactly what you're trying to do I can't be sure.
Since you've changed your question I think I know what you want to do so I've edited my answer. As John mentioned in his post the first thing you need to do is call setContentView
directly after the call to super.onCreate
. This means you will be able to access the TextView from your xml layout and change its text to the text which has been passed into your activity. I will give an example below.
Firstly you need to add an id to your text view in the layout file called activity_display_message.xml:
<TextView
android:id="@+id/my_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/message"/>
Then, if I've understood what you want to do correctly your onCreate
method contain the following:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
TextView textView = (TextView)findViewById(R.id.my_text_view);
textView.setTextSize(40);
textView.setText(message);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…