在autocompletetextview上删除自动对焦

问题描述 投票:-1回答:4

我在同一页面中使用自动完成textview和listview。在listview中,我使用的是Edittext(动态)。每当我试图关注listview下的EditText时,它都会专注于自动完成textview。请帮我控制两个视图的重点。如何停止自动完成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>

VIE W上。 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>
android android-edittext focus autocompletetextview
4个回答
3
投票

想要停止焦点:你可以使用view.clearFocus();想要集中注意力:你可以使用view.requestFocus();

它会帮助你。


2
投票

将这些添加到父视图(线性布局)。

android:focusable="true"
android:focusableInTouchMode="true"

这会将焦点转移到父视图。

[这在横向模式下不起作用!]


1
投票

从这个其他帖子Disable auto focus on edit text

聚焦父布局而不是编辑文本

main.xml中

<LinearLayout
    android:id="@+id/linear"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="2"
    android:focusable="true" 
    android:focusableInTouchMode="true" >

如果你想在view.xml中做同样的事情

<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"
    android:focusable="true" 
    android:focusableInTouchMode="true" >

-1
投票

只需将此行添加到EditText项目即可

`android:focusable="false"`

像这样

 <EditText
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.8"
    android:hint="Write a comment..."
    android:focusable="false"
    android:maxLines="1" />
© www.soinside.com 2019 - 2024. All rights reserved.