1
私はScrollViewをListViewのように動作させようとしています。 すべての行は動的に追加されたTextViewになります。 だから私はこのコードTextViewをAndroid上でScrollViewに動的に追加する
this.scrollView = (ScrollView) findViewById(R.id.scrollView1);
this.linearLayout = (LinearLayout) findViewById(R.id.linearLayout2);
this.linearLayout.setOrientation(LinearLayout.VERTICAL);
TextView[] tx = new TextView[10];
for (int i = 0; i < 10; i++) {
tx[i] = new TextView(this);
tx[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
tx[i].setText("This is the textviewNo" + i);
this.linearLayout.addView(tx[i]);
}
this.scrollView.addView(this.linearLayout);
setContentView(this.scrollView);
を試みるが、私は間違って何行this.scrollView.addView(this.linearLayout) で
10-28 13:35:59.120: ERROR/AndroidRuntime(2346): Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
この例外を取得しますか? ありがとう