看在Android的动态文本 [英] Viewing Dynamic text in Android
问题描述
我要打印你好+在文本框中的书面文字(正如我在前面贴)。这里的code我已经做了。而不是打印您好+书面文字,它的点击按钮后才能打印你好,但是
任何建议将AP preciated。谢谢你。
公共类myActivity1延伸活动{
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
/ * //测试添加按钮
的setContentView(R.layout.content_layout_id);
* /
最后的TextView nameText =(TextView中)findViewById(R.id.entry);
//最后的TextView TV1 =新的TextView(本);
最后的TextView TV2 =新的TextView(本);
tv2.setText(你好+ nameText.getText()的toString());
最后Button按钮=(按钮)findViewById(R.id.Button01);
button.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(视图v){
的setContentView(TV2);
}
});
}
}
这不是以后你好打印任何东西,因为 nameText
是空的。
现在,也许 nameText
是一个真正的的EditText
,和你想在运行时填入。如果是这样,你需要检查 nameText
的内容在 OnClickListener
。现在,你检查它在的onCreate()
,用户界面甚至psented用户$ P $之前。
I am trying to print Hello + written text in text box (As I posted earlier). Here's the code I have done. But instead of printing Hello+written text, its only printing Hello after clicking the button.
Any suggestion will be appreciated. Thanks.
public class myActivity1 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* // testing add button
setContentView(R.layout.content_layout_id);
*/
final TextView nameText= (TextView) findViewById(R.id.entry);
//final TextView tv1 = new TextView(this);
final TextView tv2 = new TextView(this);
tv2.setText("Hello"+ nameText.getText().toString());
final Button button = (Button) findViewById(R.id.Button01);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setContentView(tv2);
}
});
}
}
It is not printing anything after "Hello", because nameText
is empty.
Now, perhaps nameText
is really an EditText
, and you are trying to fill it in at runtime. If so, you need to check the contents of nameText
in the OnClickListener
. Right now, you are checking it in onCreate()
, before the UI is even presented to the user.
这篇关于看在Android的动态文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!