android - dynamic generation of layout view inside scrollbar -


i facing issue need generate dynamic views 1 below inside scrollview. views should generated after button click.

for first button click, working fine after second click failing error "java.lang.illegalstateexception: scrollview can host 1 direct child"

can me fixed.

my main activity layout scrollview activity_main.xml:

<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> 

and view layout need attached scrollview address_layout.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" /> 

in main activity, inside button click listener:

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)); 

the android scrollview supports child throws java.lang.illegalstateexception. should add 1 linearlayout or relative layout in scrollview , add children layout.

    <scrollview android:id="@+id/scview" android:layout_width="match_parent" android:layout_height="wrap_content"         android:layout_below="@id/spincity"> <linearlayout android:id="@+id/layout"  android:layout_width="match_parent" android:layout_height="wrap_content">     </linearlayout>     </scrollview> 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -