安卓开发的新生,刚刚搭好eclipse和AVD等等东东,写了个hello,world程序,运行倒是成功了。
但是我把hello,world程序的输出改成“大家好”,AVD输出竟然还是“hello,world”,崩溃了,搜遍网上没找到为什么,哪位大神能指点一二。源代码如下
package helloworld.test;import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv=new TextView(this);
tv.setText("大家好"); //原来是 tv.setText("hello,world!");
setContentView(R.layout.main);
}
}
但是我把hello,world程序的输出改成“大家好”,AVD输出竟然还是“hello,world”,崩溃了,搜遍网上没找到为什么,哪位大神能指点一二。源代码如下
package helloworld.test;import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv=new TextView(this);
tv.setText("大家好"); //原来是 tv.setText("hello,world!");
setContentView(R.layout.main);
}
}
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv=(TextView)findviewbyid(R.id.xxx)
tv.setText("大家好");
}
tv.setText("大家好"); //原来是 tv.setText("hello,world!");
以上两句代码没有用的,你需要用findViewById(R.id.xxx)去对layout中的TextView设置文本,才会变的
public class HelloActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv=new TextView(this);
tv.setText("大家好"); //原来是 tv.setText("hello,world!");
setContentView(tv);
}
}