你好,我正在尝试显示一个带有TextView
. 我正在动态执行此操作,这是代码:
LinearLayout layout=(LinearLayout) this.findViewById(R.id.Layout);
EditText editText=(EditText) this.findViewById(R.id.textView);
Button button=(Button) this.findViewById(R.id.btnAdd);
LayoutParams lparams = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv=new TextView(this);
tv.setLayoutParams(lparams);
tv.setText(display);
this.layout.addView(tv);
,但它在this.layout.addView(tv);
你能告诉我我做错了什么吗?
提前非常感谢!
更新(完整活动代码):
public class CalendarDate extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calendar_date);
Bundle extras = getIntent().getExtras();
String dday = extras.getString("currentday");
String dmonth =extras.getString("currentmonth");
String dyear = extras.getString("currentyear");
ActionBar ab = getActionBar();
ab.setTitle(dday+"/"+dmonth+"/"+dyear );
Bundle extraz =getIntent().getExtras();
String display = extras.getString("EXTRA_MESSAGE");
setContentView(R.layout.activity_calendar_date);
LinearLayout layout=(LinearLayout) this.findViewById(R.id.Layout);
EditText editText=(EditText) this.findViewById(R.id.textView);
Button button=(Button) this.findViewById(R.id.btnAdd);
LayoutParams lparams = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv=new TextView(this);
tv.setLayoutParams(lparams);
tv.setText(display);
layout.addView(tv);
}