2017-11-27 3 views
0

enter image description here同じコンテナを使用する複数のフラグメントがあり、別のフラグメントにフラグメントが追加された場合、最近追加されたフラグメントのビュー。私はonBackstackChangeListener()を使用して解決しようとしましたが、動作していないようです。画像のように、私はPin Entryフラグメントだけにフォーカスしたいが、Pin Entry Fragmentの後ろのフラグメントの "Enter"ボタンにもフォーカスが移っている。助けてください。複数のフラグメントが追加されたコンテナ内の1つのフラグメントのみにフォーカスを限定する

+0

フラグメントの最上位ルートをxmlでクリック可能にします。 – ADM

+0

@ADMもう少し説明してください... –

答えて

0

すべてのフラグメントに単一のコンテナを使用している場合は、フラグメントの最上位のルートをクリック可能に設定する必要があります。さもなければ、後ろのフラグメントがクリック可能なアイテムのためのフォーカスをつかむことができます。例えば以下の断片のレイアウトを見てください。

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:clickable="true" 
android:orientation="vertical"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right" 
    android:background="?selectableItemBackground" 
    android:gravity="center_vertical" 
    android:textColor="@color/white" 
    android:textSize="@dimen/normal_text" /> 
</LinearLayout> 
+0

私は恐れています、これは私のコードではうまくいかないようです。とにかくありがとう。 –

+0

入力ピンの断片がwrap_contentである可能性があります。親を埋める場合は作成してください。 – ADM

+0

@ NishanKhadkaあなたは解決策を見つけることができますか、私は同じ問題を抱えています – ysfcyln

0

私はこの問題を回避する方法を見つけましたが、実際の解決策ではありません。最高の答えは正解とマークされます。

ワーキングアラウンド: レイアウトの周囲にフォーカスを置いて、そのまま滞在するビューを追加します。例:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    android:orientation="horizontal"/> 
<View 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:focusable="true" 
     android:id="@+id/left_view"/> 
<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal"> 
<TextView 
       android:id="@+id/buyOrWatch" 
       android:layout_width="90dp" 
       android:layout_height="30dp" 
       android:layout_margin="5dp" 
       android:background="@drawable/movie_buy_selector" 
       android:focusable="true" 
       android:gravity="center" 
       android:text="@string/buy" 
       android:textColor="@color/color_white" /> 

      <TextView 
       android:id="@+id/preview" 
       android:layout_width="90dp" 
       android:layout_height="30dp" 
       android:layout_margin="5dp" 
       android:layout_marginTop="15dp" 
       android:background="@drawable/movie_buy_selector" 
       android:focusable="true" 
       android:gravity="center" 
       android:text="@string/preview" 
       android:textColor="@color/color_white" /> 
     </LinearLayout> 

<View 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:focusable="true" 
      android:id="@+id/right_view"/> 

レイアウトを、0dp幅の2つのフォーカス可能なビューの間にtextviewsで配置しました。 フラグメントクラスで、これらのビューをバインドし、次にこれらのビューに対してfocusChangeListener()を定義します。断片が表示されているように、例えばleftView結合がTextViewandroid:id="@+id/buyOrWatch"を有するID android:id="@+id/left_view"buyOrWatchと表示する場合、次いで、

leftView.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
      @Override 
      public void onFocusChange(View view, boolean hasFocus) { 
       if(hasFocus){ 
        buyOrWatch.requestFocus(); 
       } 
      } 
     }); 

あなたがあれば、次いで、上記のような各ビューの同様のフォーカス変更リスナーを定義することができ、フォーカスとステーその断片にこれが誰かを助けることを望みます。

関連する問題