问题
setText(), setTextsize() and addView is not working. It is shown as cannot resolve symbol type.
Intent intent = getIntent();
String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.content);
layout.addView(textView);
回答1:
You can't use methods such as add and find view by id before the layout is inflated. Verifý that setContentView is called before.
If it does, look at the value of message with a log.
回答2:
Have you noticed this
``
At the end of this line
TextView textView = new TextView(this);``
回答3:
Intent intent = getIntent();
String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);
TextView textView;
{
textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
}
RelativeLayout layout;
{
layout = (RelativeLayout) findViewById(R.id.content);
layout.addView(textView);
}
this solved my errors.
来源:https://stackoverflow.com/questions/38330411/settext-not-working