setText() not working

≡放荡痞女 提交于 2020-01-07 02:07:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!