2017-02-16 10 views
2

私はEditTextに問題があります。私のアプリでは、CCBBがETに挿入されてフォーカスがListViewに移動したときにコードバースキャナーで取得するコードバーが必要ですが、フォーカスを戻そうとしました以下を含む:フォーカスを設定EditText android

et.requestFocus();

しかし、焦点は、リストビューの無効焦点を当ててみましたまた、リストビューの移動はありません。

私は、15秒ごとに発言するTTSのスレッドを持っており、スレッドにet.requestFocus()を入れていますが、それはうまく動作しません。

ありがとうございました!私はXMLで、このコードでそれを達成している


は:

<EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="number" 
     android:ems="10" 
     android:hint="@string/ccbb" 
     android:id="@+id/codigobarra" 
     android:nextFocusDown="@id/codigobarra"/> 
+0

あなたはandroid:descendantFocusability = "blocksDescendants"を設定しましたか? – user3040153

+0

requestWindowFeature(Window.FEATURE_NO_TITLE)を使用していますか?それがあればそれを取り除く。 – Rajan1404930

答えて

0

あなたlistItemのの親ビューに、このandroid:descendantFocusability="blocksDescendants"プロパティを追加して、XML以下のようなandroid:focusableInTouchMode="true"EditTextインチ

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/activity_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:descendantFocusability="blocksDescendants" 
     tools:context="com.cj.myapplication.MainActivity"> 

     <EditText 
      android:id="@+id/editText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:focusableInTouchMode="true" 
      android:text="Name" /> 

    </RelativeLayout> 
+0

ありがとう!私はそれを試みましたが、うまくいきません。フォーカスは再び変化した。 – Gannon

+0

edittextのフォーカスをandroid:focusable = "false" –

+0

に変更できます。edittextをandroid:focusable = "false"に変更すると、edittextにコードバーを挿入できません。 – Gannon

0

これを試してください。それはあなたを助けるでしょう。

listview.post(new Runnable() { 
    @Override 
    public void run() { 
     et.requestFocus(); 
     et.setFocusable(true); 
     et.setFocusableInTouchMode(true); 
    } 
関連する問題