-1
你好,我正在嘗試顯示一個字符串與TextView
。我動態這樣做的,這是代碼:Android:顯示帶有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);
}
什麼是錯誤? this.layout.addView(tv)中的 – Manu
;說佈局不能解決或不是一個領域。 – SoCo
嘗試:layout.addView(tv); – Tobiel