Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText in scroll view in android

I try to create a from application, in the app I have a lengthy form which I want to be in a scroll view, But when I add EditText to the scrollView ..the eclipse shows some error in its designer view.

error!
IllegalStateException: ScrollView can host only one direct child
Exception details are logged in Window > Show View > Error Log

Any one have an idea to crack it out?


I have included this code after getting a solution for the above trouble..!

Now the EditText is not showing any typed text, it just gives some suggestions...!

I have the following XML :

<ScrollView
android:id="@+id/widget64"
android:layout_width="320px"
android:layout_height="358px"
android:fillViewport="true"
android:isScrollContainer="true"
android:saveEnabled="true">
<TableLayout
android:id="@+id/widget58"
android:layout_width="320px"
android:layout_height="65px"
android:orientation="vertical"
>
<TableRow
android:id="@+id/widget60"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/user"
android:text="User"
android:textColor="#000000">
</TextView>
</TableRow>
<TableRow
android:id="@+id/widget60"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
>
<EditText
android:id="@+id/users_first_name" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:hint="First Name"
android:focusable="true"
android:inputType="textPersonName"
android:enabled="true"
android:ems="15">
</EditText>
</TableRow>
</TableLayout>
</ScrollView>

Found the trouble..... My emulator key was set to Chinese instead of English...

like image 795
rahul Avatar asked Feb 04 '11 06:02

rahul


2 Answers

First add any layout to that scrollview and then add edittext to that layout.Then automatically u got the scrolling for that edittext .For Ex:add Linearlayout to that scrollview and then add editText to taht linearlayout.

like image 169
Pinki Avatar answered Oct 19 '22 11:10

Pinki


Yes, ScrollVew can have only one child. For this do something like this

<ScrollView
   fillViewPortView = "true">

    <RelativeLayout>
          // Design the entire layout in here
          // Put your elements one below the other. It will automatically scroll
          // dont forget to setFillViewPort view to true in ScrollView
    </RelativeLayout>
</ScrollView>

This will solve the problem for sure
Hope his help : )

like image 37
Rohit Sharma Avatar answered Oct 19 '22 10:10

Rohit Sharma