Santhosh
Santhosh

Reputation: 5016

Keyboard is hiding the EditText in Android

I have two EditText fields in Listview item layout. A new item will get added as the first row in Listview on click of a button. And I'm able to enter the text into both the fields.

Here is my code:

<ListView 
android:id="@+id/items_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animationCache="false"
android:background="@color/white"
android:descendantFocusability="afterDescendants"
android:fadingEdge="none"
android:fadingEdgeLength="0dp"
android:focusable="true"
android:divider="@android:color/transparent"
android:overScrollMode="never"
android:scrollingCache="false"
android:smoothScrollbar="true" />

getView() of Adapter :

 @Override
public View getView(final int position, View convertView, final ViewGroup parent) {

    final ViewHolder viewHolder;
    if (convertView == null || !(convertView.getTag() instanceof ViewHolder)) {
        viewHolder = new ViewHolder();
        convertView = inflater.inflate(R.layout.items_listview_item, null);
        viewHolder.quantity = (EditText) convertView.findViewById(R.id.quantity_editText);
        viewHolder.description = (EditText) convertView.findViewById(R.id.description_editText);
        viewHolder.description.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    viewHolder.position = position;
    viewHolder.description.setText(itemsArrayList.get(position).getDescription());
    viewHolder.quantity.setText(itemsArrayList.get(position).getQuantity());

    viewHolder.quantity.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }
        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }
        @Override
        public void afterTextChanged(Editable arg0) {
            itemsArrayList.get(viewHolder.position).setQuantity(arg0.toString());
        }
    });

    viewHolder.description.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }
        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }
        @Override
        public void afterTextChanged(Editable arg0) {
            itemsArrayList.get(viewHolder.position).setDescription(arg0.toString());
        }
    });


    return convertView;
}


 private static class ViewHolder {
    EditText description;
    EditText quantity;
    int position;
}

And I'm using adjustPan for my activity in manifest.

Here is my Issue : This is working fine on all devices that I have tested, But on Samsung Galaxy-Tab2 (10-inch Tablet), When I add a new item and tap 2nd EditText (i.e description field) the keyboard is showing just below the description field, which is fine. Now if I press any key then the keyboard is covering the description field. I cannot see what exactly is being entered into the field. 2nd EditText is completely hidden by keyboard. And this is not happening with 1st EditText field. Where I'm going wrong? Why is it not working as expected on galaxy-Tab2? Please help me. Thanks in advance.

Upvotes: 0

Views: 483

Answers (2)

bhumika rijiya
bhumika rijiya

Reputation: 440

Try this,

 android:windowSoftInputMode="adjustResize".

If this is not enough, you might need to add the property android:fitsSystemWindows="true"

to the root layout containing your EditText.

OR

change your layout according this, Dont miss the line which is

android:isScrollContainer="true"

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:isScrollContainer="true"
    android:orientation="vertical">

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:background="#000000"
        android:padding="0dp"
        android:stretchColumns="*">
        ...
    </TableLayout>
</ScrollView>

Upvotes: 0

santoXme
santoXme

Reputation: 802

Add this line to your Manifest :

android:windowSoftInputMode="adjustPan|adjustResize"

or you can give this line to your oncreate :

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Upvotes: 0

Related Questions