在for循环中添加textViews

Ada*_*dam 0 android android-layout

      scrollview = (ScrollView)findViewById(R.id.detailedScrollView);


  for (Quotation quotation : object.quotes){

          TextView quote = new TextView(this);
          quote.setText(quotation.getQuote());
          quote.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
          scrollview.addView(quote);


      }
Run Code Online (Sandbox Code Playgroud)

假设有三个引号,那么我想要三个textViews.但是,上面的代码崩溃了我的应用程序.有任何明显的错误吗?这是我得到的错误:

11-06 17:35:53.214: E/AndroidRuntime(1430): java.lang.IllegalStateException: ScrollView can host only one direct child
Run Code Online (Sandbox Code Playgroud)

Thi*_*rry 6

您无法直接在滚动视图中添加视图.scrollview只能包含一个布局对象.您需要做的是在滚动视图中添加linearlayout,然后将textview添加到linearlayout