final TextView tv = new TextView(this);
final RelativeLayout rL = new RelativeLayout(this);
final EditText editText = (EditText)findViewById(R.id.editText);
final Button b1 = (Button)findViewById(R.id.b1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rL.addView(tv);
tv.setText(editText.getText());
editText.setText("");
}
});
在我的onCreate方法,但是当文本输入和我的按钮被按下我的TextView不会在屏幕上显示出来?有没有代码可以设置在手机屏幕上的位置?
您是以编程方式或以XML格式创建'textView'吗?也可以用'public'替换'final'。 – TronicZomB
以编程方式,如我在标题中所述:) –
您添加文本视图的相对布局在屏幕上不可见。您需要使用findViewById()来获取对RelativeLayout的引用,就像您使用button和EditText一样,而不是使用新的RelativeLayout – FoamyGuy