SearchFunctionality to edittext in Android

You need to make changes in xml. Change your parent to Relative so that list should open on the edittext not below it. Because in case of linear layout with vertical orientation when you ll make listview visible then it ll occupy space vertically and definitely the edit text will move down. If you understood the point then its good else post your complete xml its not complete xml you have posted here. I ll make changes in it

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dipak"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/darker_gray"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#5e0d3a"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <Button
        android:id="@+id/tables_item"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="15dp"
        android:layout_marginTop="40dp"
        android:text="abc"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/toolbar1"
        android:textAlignment="center"
        android:textSize="15dp" />

        <EditText
            android:id="@+id/selectitem"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="10dp"
            android:hint="Select Item"
            android:padding="10dp"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/tables_item"
            android:textAlignment="center"
            android:textColor="#000" />        

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:orientation="vertical"
        android:layout_below="@id/selectitem">

        <EditText
            android:id="@+id/quantitybox_itemorder"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="10dp"
            android:digits="0123456789."
            android:hint="Quantity"
            android:padding="10dp"
            android:textAlignment="center"
            android:textColor="#000" />

        <EditText
            android:id="@+id/Description_item"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="10dp"
            android:hint="Description of item"
            android:padding="10dp"
            android:textAlignment="center"
            android:textColor="#000" />

        <Button
            android:id="@+id/add_order_item"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="10dp"
            android:layout_marginLeft="-10dp"
            android:layout_marginRight="-10dp"
            android:layout_marginTop="-10dp"
            android:text="Add Order"
            android:textAlignment="center"
            android:textColor="@android:color/primary_text_dark"
            android:textSize="20dp" />
        <Button
            android:id="@+id/showitem"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="10dp"
            android:layout_marginLeft="-10dp"
            android:layout_marginRight="-10dp"
            android:layout_marginTop="-10dp"
            android:text="Show Inserted"
            android:textAlignment="center"
            android:textColor="@android:color/primary_text_dark"
            android:textSize="20dp" />
    </LinearLayout>

    <ListView
        android:id="@+id/list_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:visibility="gone"
        android:layout_below="@id/selectitem"/>
</RelativeLayout>

Have a look on this now when you will make your listview visible then the edittext will not moe down or there wil not be space below. After selecting item from listview make its visibility gone programmatically.
If you feel any problem let me know.

Leave a Comment