user2826275
user2826275

Reputation: 1

Softkeyboard hides text area on focusing : Android

I have multiple textareas in the app. When I click on that to input, keyboard popup (android tab). But the textarea stays where it's on that page. How can I scroll page when keyboard pops up.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >



<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

    <TableRow
        android:gravity="center"
        android:paddingTop="10px" >

        <TextView
            android:id="@+id/status"
            android:layout_width="wrap_content"
            android:layout_gravity="center"
            android:layout_span="2"
            android:text="Registration Form"
            android:textColor="#000000"
            android:textSize="15sp"/>
    </TableRow>

          <TableRow android:layout_marginTop="20dip" >

        <TextView
            android:id="@+id/firstName1"
            android:layout_width="wrap_content"
            android:layout_marginLeft="20dip"
            android:textColor="#000000"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/firstName"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:layout_weight="1"
            android:inputType="text"
            android:singleLine="true"
            android:maxLength="100"
            android:textColor="#000000"
            android:textSize="15sp" >

            <requestFocus />
        </EditText>
    </TableRow>

    <TableRow android:layout_marginTop="20dip" >

        <TextView
            android:id="@+id/middleName1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:text=" Middle Name :"
            android:textColor="#000000"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/middleName"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:layout_weight="1" 
            android:inputType="text"
            android:singleLine="true"
            android:maxLength="100"
            android:textColor="#000000"
            android:textSize="15sp"/>
    </TableRow>

       <TableRow android:layout_marginTop="20dip" >

        <TextView
            android:id="@+id/lastName1"
            android:layout_width="wrap_content"
            android:layout_marginLeft="20dip"
            android:textColor="#000000"
            android:textSize="15sp"/>

        <EditText
            android:id="@+id/lastName"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:layout_weight="1"
            android:inputType="text"
            android:singleLine="true"
            android:maxLength="100"
            android:textColor="#000000"
            android:textSize="15sp" >


        </EditText>
    </TableRow>

    <TableRow android:layout_marginTop="20dip" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:text=" ITS Id(Optional) :"
            android:textColor="#000000"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/itsId"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:layout_weight="1"
            android:inputType="number"
            android:maxLength="8" />

    </TableRow>
    <TableRow android:layout_marginTop="20dip" >

        <TextView
            android:id="@+id/userName1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:textColor="#000000"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/userName"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:layout_weight="1"
            android:inputType="text" 
            android:singleLine="true"
            android:maxLength="50"
            android:textColor="#000000"
            android:textSize="15sp"/>

    </TableRow>


    <TableRow android:layout_marginTop="20dip" >

        <TextView
            android:id="@+id/password1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:textColor="#000000"
            android:textSize="15sp"/>

        <EditText
            android:id="@+id/password"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:layout_weight="1"
            android:inputType="textPassword"
            android:maxLength="8"
            android:textColor="#000000"
            android:textSize="15sp" />

    </TableRow>


    <TableRow android:layout_marginTop="20dip" >

        <TextView
            android:id="@+id/confirmPassword1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:textColor="#000000"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/confirmPassword"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:layout_weight="1"
            android:inputType="textPassword"
            android:maxLength="8"
            android:textColor="#000000"
            android:textSize="15sp" />

    </TableRow>


    <TableRow android:layout_marginTop="20dip" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:text=" Email :"
            android:textColor="#000000"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/email"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:layout_weight="1"
            android:singleLine="true"
            android:inputType="textEmailAddress"
            android:maxLength="200"
            android:textColor="#000000"
            android:textSize="15sp" />

    </TableRow>

    <TableRow android:layout_marginTop="20dip" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:text=" Gender :"
            android:textColor="#000000"
            android:textSize="15sp" />

        <Spinner
            android:id="@+id/gender"
            android:layout_height="wrap_content"
             android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:layout_weight="1"
            android:entries="@array/gender_array" />

    </TableRow>
   <TableRow android:layout_marginTop="20dip" >


        <CheckBox
            android:id="@+id/profile"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:textColor="#000000"
            android:textSize="15sp"
            android:text="Keep Private" />



    </TableRow>

    <TableRow android:layout_marginTop="20dip" >


        <Button
            android:id="@+id/save"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="true"
            android:onClick="addNewProfile"
            android:text="Submit" />


         <Button
            android:id="@+id/cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="true"
            android:onClick="cancelActivity"
            android:text="Cancel" />

    </TableRow>
  </TableLayout>
</ScrollView>


<activity android:label="Registration" android:name="Registration"       android:windowSoftInputMode="adjustPan"></activity>    

I used adjustPan but this one also not working. Please tell me how can I scroll up field when softKeyboard will apppear?

Upvotes: 0

Views: 255

Answers (1)

Naddy
Naddy

Reputation: 2674

private final void focusOnView(){
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            your_scrollview.scrollTo(0, your_EditBox.getBottom());
        }
    });
}

Upvotes: 1

Related Questions