HorizontalScrollView를 통해 ArrayList의 사이즈만큼 버튼을 생성하는 것을 만들고 싶은데요
에러가 나네요...
XML>>
<HorizontalScrollView
android:id="@+id/category_horizontablscrollview"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:fillViewport="true"
android:scrollbarSize="5dip">
<LinearLayout
android:id="@+id/category_layout"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
</HorizontalScrollView>
Android code>>
mScrollView = (HorizontalScrollView) findViewById(R.id.category_horizontablscrollview);
LinearLayout categoryLinearLayout = new LinearLayout(this);
categoryLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
for (int i = 0; i < cateList.size(); i++){
final Button categoryButton = new Button (this);
categoryButton.setTag(i);
categoryLinearLayout.addView(categoryButton);
categoryButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Log.e("Tag",""+categoryButton.getTag());
}
});
}
mScrollView.addView(categoryLinearLayout);
Error >>
03-17 16:14:22.940: E/AndroidRuntime(8534): Caused by: java.lang.IllegalStateException: HorizontalScrollView can host only one direct child
이상입니다..
---> 자답입니다
View가 한개만 가능하기 때문에
HorizontalScrollView 안을 지워주니 되네요 ㅎㅎ