Stop dpad focus going outside current fragment in android -


my current app requires control using d-pad remote.

using focus/select, automatic calculation of nearest neighbour works expected want limit up, down, left, right movements occur in current fragment contains focused view, , cancel change of focus before moves fragment.

i programatically changing focus new fragment upon selecting view.

is possible do? can assume onfocuschange() event allow me check whether new focus outside fragment , return no luck here...

in short, can call setdescendantfocusability(viewgroup.focus_block_descendants) on container holds fragment block focusability fragment descendants. bring focusability can call setdescendantfocusability(viewgroup.focus_after_descendants)

details:

suppose have framelayout containing 2 fragments, 1 on top another, , want limit focus navigation top_fragment when in place , back_fragment otherwise:

<?xml version="1.0" encoding="utf-8"?> <framelayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">      <framelayout         android:id="@+id/back_fragment"         android:layout_width="match_parent"         android:layout_height="match_parent"/>      <framelayout         android:id="@+id/top_fragment"         android:layout_width="match_parent"         android:layout_height="match_parent"/>  </framelayout>  

first call addonbackstackchangedlistener() on instance of fragmentmanager provide backstack listener, can write focusability controlling code method setdescendantfocusability. can use getfragmentmanager().findfragmentby* find out fragments used now, what's on top etc. , set descendant focusability flags appropriately. when replacing top_fragment container, add transaction backstack addtobackstack() method. way able change focusability settings when backstack changes, not when you're adding fragment, when you're popping well.


Comments

Popular posts from this blog

c++ - Linked List error when inserting for the last time -

java - activate/deactivate sonar maven plugin by profile? -

java - What is the difference between String. and String.this. ? -