我正在尝试使用Google University Android lab1,要求您根据从其他活动通过Intent传递的值更改TextView的文本内容.
我尝试了其余的代码,但是......当我添加"tv.settext(...)行"时,为什么我的应用强行关闭?
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
* Fetch and display passed string.
*/
TextView tv = (TextView) findViewById(R.id.HelloTV);
Bundle extras = this.getIntent().getExtras();
if (extras != null) {
String nameStr = extras.get("Username").toString();
if (nameStr != null) {
tv.setText("Hello "+nameStr);
}
}
setContentView(R.layout.main);
}
}
Run Code Online (Sandbox Code Playgroud)