0
스크롤 뷰 내부에 다른 동적 뷰를 생성해야하는 문제가 있습니다. 뷰는 버튼 클릭 후 생성되어야합니다. 첫 번째 버튼 클릭에 대한 동적 스크롤 막대 레이아웃보기 생성
, 잘 작동하지만, 두 번째 이후는 오류와 함께 실패 클릭합니다 "java.lang.IllegalStateException :있는 ScrollView는 하나의 직접 아이 호스팅 할 수 있습니다"는 사람이 고정을 얻기 위해 나를 도울 수
을 . 있는 ScrollView가 activity_main.xml입니다내 주요 활동 레이아웃 : 주요 활동에서
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/center" android:layout_width="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:text="@string/hello_world" android:layout_margin="10dp"
android:textColor="#FF0000" android:textSize="30dp"
/>
, 내부 :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" android:layout_width="match_parent" android:layout_height="match_parent"
android:id="@+id/parentRL">
<Spinner android:id="@+id/spinState" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<Spinner android:id="@+id/spinCity" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/spinState"/>
<TextView android:id="@+id/cityCount" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@id/spinCity" android:layout_below="@id/spinState" android:layout_marginLeft="5dp"
android:textIsSelectable="false"/>
<Button android:id="@+id/showAddress" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@id/spinState" android:onClick="populateAddress" android:text="Search"/>
<ScrollView android:id="@+id/scView" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_below="@id/spinCity">
</ScrollView>
</RelativeLayout>
그리고있는 ScrollView 부착 할 필요가있는 뷰 레이아웃은 address_layout.xml입니다 버튼 클릭 리스너 :
LayoutInflater inflater = (LayoutInflater)MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = inflater.inflate(R.layout.address_layout, null);
TextView _c_ = (TextView)(myView.findViewById(R.id.center));
_c_.setVisibility(View.VISIBLE);
_c_.setText(my_random_number);
View insertPoint = findViewById(R.id.scView);
((ViewGroup) insertPoint).addView(myView, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));