I am using autocomplete textview and listview in a same page. in the listview, i am using Edittext (dynamically). whenever i am trying to focus on EditText under the listview, it is focusing on autocomplete textview. Please help me to control the focus of two views. how to stop the default focus of autocomplete textview.
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backgroundpattern"
android:orientation="vertical"
tools:context="app.inedge.inedgeactivity.ui.sales.SkuSalesActivity" >
<TextView
android:id="@+id/txt_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/header"
android:gravity="center"
android:padding="3dp"
android:text="@string/title_activity_sku_sales"
android:textColor="@color/header"
android:textSize="24sp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2" >
<AutoCompleteTextView
android:id="@+id/et_sku"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_weight="1.75"
android:background="@drawable/edittext_bg"
android:cursorVisible="false"
android:dropDownVerticalOffset="5dp"
android:dropDownWidth="wrap_content"
android:gravity="center"
android:hint="@string/search"
android:inputType="textAutoComplete|textAutoCorrect"
android:nextFocusLeft="@+id/et_sku"
android:nextFocusUp="@+id/et_sku"
android:padding="3dp"
android:popupBackground="@color/white"
android:textColor="@color/black" />
<Button
android:id="@+id/btnClose"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_weight="0.25"
android:background="@android:drawable/ic_notification_clear_all" />
</LinearLayout>
<Spinner
android:id="@+id/sp_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:background="@android:drawable/btn_dropdown" />
<Spinner
android:id="@+id/sp_sub_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@android:drawable/btn_dropdown" />
<TextView
android:id="@+id/txt_sku_item_lbl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="@color/gray"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="@string/sku_it"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold" />
<ListView
android:id="@+id/sku_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:descendantFocusability="afterDescendants" >
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="@+id/but_addItem_sku"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:background="@drawable/buttonorange_shape"
android:gravity="center"
android:text="@string/confirmbutton"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linsku"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt_input_name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="Product 1"
android:textColor="@color/header"
android:textStyle="bold" />
<EditText
android:id="@+id/txt_input_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/edittext_bg"
android:digits="0123456789"
android:ems="5"
android:gravity="right"
android:imeActionLabel="DONE"
android:imeActionId="@+id/action_add"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="10"
android:singleLine="true"
android:textColor="@color/gray" >
</EditText>
</LinearLayout>
Want to stop focus: You can use view.clearFocus();
Want to focus: You can use view.requestFocus();
It will helps you.