2012-02-11 23 views
5

Estoy desarrollando una aplicación para Google TV donde toda la navegación se realizará usando D-Pad/Keyboard.Cómo configurar el próximo control enfocable de Android ActionBar programáticamente

Mi actividad tiene una barra de acciones y algunas listas horizontalmente debajo de ella. dice lista A, B & C. Listas B & C cargar datos basados ​​en el elemento seleccionado de la lista A .. por lo que pueden/no pueden cargar datos.

problemas es que cuando la Barra de acciones tiene el foco y presiono la tecla D-Pad, el foco se pierde y no se transfiere a la lista C (o B si C tiene ningún dato) .. Y?

Para lograr esto, he intentado establecer el siguiente punto de vista de la Barra de acciones enfocable programáticamente como seguir

getActionBar().getCustomView().setNextFocusDownId(R.Id.list_C_id); 

pero sin trabajar.

También intenté verificar la jerarquía del diseño utilizando Hierarchy Viewer ... pero, francamente, no entendí qué hacer con sus hallazgos.

¿Cómo puedo configurar el siguiente control enfocable de Android ActionBar mediante programación?

Cualquier ayuda es muy apreciada.

XML de actividad es el siguiente:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainContainer" style="@style/main" > 

<!-- Splash Screen --> 
<LinearLayout 
    android:id="@+id/splash_screen" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/welcome" 
    android:orientation="vertical" > 
</LinearLayout> 

<!-- main content holder.. it is shown afetr some time of showing above splash screen --> 
<LinearLayout 
    android:id="@+id/main_content_screen" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:focusable="true" 
    android:visibility="invisible"> 

    <!-- All Packages List --> 

    <LinearLayout 
     android:layout_width="205dp" 
     android:layout_height="match_parent" 
     android:background="@drawable/content_round_bg" 
     android:focusable="true" 
     android:orientation="vertical" > 

     <!-- Header of Packages--> 
     <RelativeLayout 
      style="@style/marginLeft5" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"     
      android:background="@drawable/content_round_bg" > 

      <ImageView 
       android:id="@+id/packagesIcon" 
       style="@style/titleIcon" 
       android:src="@drawable/packages" > 
      </ImageView> 

      <TextView 
       style="@style/title" 
       android:layout_toRightOf="@+id/packagesIcon" 
       android:text="Packages" > 
      </TextView> 

      <ProgressBar 
       android:id="@+id/progressBarPackages" 
       style="@style/progressBar" /> 
     </RelativeLayout> 

     <!-- <View style="@style/horizontalSeperator" /> --> 

     <ListView 
      android:id="@+id/allPackagesList" 
      style="@style/list" 
      android:nextFocusRight="@+id/gridChannels"> 
     </ListView> 

     <!-- Message which is hidden by default and is made visible if list has no data --> 
     <LinearLayout 
      android:id="@+id/packageNotFound" 
      style="@style/emptyListIdentifier" > 

      <ImageView 
       style="@style/titleIcon" 
       android:src="@drawable/info" > 
      </ImageView> 

      <TextView 
       style="@style/emptyListIdentifierText" 
       android:layout_marginLeft="5dp" 
       android:text="Packages not available" > 
      </TextView> 
     </LinearLayout> 
    </LinearLayout> 

    <View style="@style/verticalSeperator" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:focusable="true" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:id="@+id/relativeLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:focusable="true" 
      android:layout_below="@+id/titleContainer" > 

      <LinearLayout 
       android:id="@+id/channelsContainer" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="0.35" 
       android:background="@drawable/content_round_bg" 
       android:focusable="true" 
       android:orientation="vertical" > 

       <!-- Header of Channels--> 
       <RelativeLayout 
        style="@style/marginLeft5" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@drawable/content_round_bg" > 

        <ImageView 
         android:id="@+id/channelsIcon" 
         style="@style/titleIcon" 
         android:src="@drawable/channels" > 
        </ImageView> 

        <TextView 
         style="@style/title" 
         android:layout_toRightOf="@+id/channelsIcon" 
         android:text="Channels" > 
        </TextView> 

        <ProgressBar 
         android:id="@+id/progressBarChannels" 
         style="@style/progressBar" /> 
       </RelativeLayout> 

       <RelativeLayout style="@style/listsContiner" android:focusable="true" > 

        <GridView 
         android:id="@+id/gridChannels" 
         style="@style/grid" 
         android:divider="#10F1F1F1" 
         android:nextFocusLeft="@+id/allPackagesList" 
         android:nextFocusRight="@+id/gridAllVODs" 
         android:numColumns="2" /> 
       </RelativeLayout> 

       <!-- Message which is hidden by default and is made visible if list has no data --> 
       <RelativeLayout 
        android:id="@+id/channelsNotFound" 
        style="@style/emptyListIdentifier" > 

        <ImageView 
         android:id="@+id/NoChannelsIcon" 
         style="@style/titleIcon" 
         android:src="@drawable/info" > 
        </ImageView> 

        <TextView 
         style="@style/emptyListIdentifierText" 
         android:layout_toRightOf="@+id/NoChannelsIcon" 
         android:text="Channels are currently not available" > 
        </TextView> 
       </RelativeLayout> 
      </LinearLayout> 

      <View style="@style/verticalSeperator" /> 

      <LinearLayout 
       android:id="@+id/vodsContainer" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="0.65"      
       android:background="@drawable/content_round_bg" 
       android:orientation="vertical" > 

       <!-- Header of VODs--> 
       <RelativeLayout 
        style="@style/marginLeft5" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@drawable/content_round_bg" > 

        <ImageView 
         android:id="@+id/VODsIcon" 
         style="@style/titleIcon" 
         android:src="@drawable/vod" > 
        </ImageView> 

        <TextView 
         style="@style/title" 
         android:layout_toRightOf="@+id/VODsIcon" 
         android:text="VOD" > 
        </TextView> 

        <ProgressBar 
         android:id="@+id/progressBarVODs" 
         style="@style/progressBar" /> 
       </RelativeLayout>      

       <RelativeLayout style="@style/listsContiner" > 
        <GridView 
         android:id="@+id/gridAllVODs" 
         style="@style/grid" 
         android:divider="#10F1F1F1" 
         android:nextFocusLeft="@+id/gridChannels" 
         android:nextFocusRight="@+id/allPackagesList" 
         android:numColumns="1" /> 
       </RelativeLayout> 

       <!-- Message which is hidden by default and is made visible if list has no data --> 

       <RelativeLayout 
        android:id="@+id/videosNotFound" 
        style="@style/emptyListIdentifier" > 

        <ImageView 
         android:id="@+id/NoVODsIcon" 
         style="@style/titleIcon" 
         android:src="@drawable/info" > 
        </ImageView> 

        <TextView 
         style="@style/emptyListIdentifierText" 
         android:layout_centerInParent="true" 
         android:layout_toRightOf="@+id/NoVODsIcon" 
         android:text="Videos are currently not available" > 
        </TextView> 
       </RelativeLayout> 
      </LinearLayout> 
     </LinearLayout> 
    </RelativeLayout> 
</LinearLayout> 

Todos los contenedores de cada Lista/Cuadrícula hasta la mayoría de Top LinearLayout han establecido android: enfocable = "true" o directamente en su estilo.

EDIT: aplicación de ejemplo que describe exactamente la pantalla de mi spp puede ser descargado desde here

favor incluya en la primera lista. Puede buscarlo por su id allPackagesList en el archivo main.xml. Olvidé insertarlo. Lo sentimos

Problemas en esta aplicación son:

  1. Focus no viene a la lista/rejas de la Barra de acciones de artículo.
  2. Navegación entre artículos actionbar lleva más de un D-Pad "izquierda" o "derecha" presiona para mover

Respuesta

0

es la lista envuelta dentro de otro contenedor? Intenta agregar android: focusable = "true" para tus listas y sus contenedores ...

+0

no funcionó ... he actualizado mi pregunta y coloqué el XML de la actividad ... puedo usar un encabezado personalizado con botones (para actuar como botones de acción) y la imagen de un logotipo ... pero no quiero ... ya que quiero usar el ActionBar incorporado. Por favor, ayúdenme a solucionarlo ya que es muy urgente – Aamir

+0

No veo ListView o ActionBar en el xml. –

+0

ListView y dos GridView están en xml ... y no agregué ActionBar en XML ... simplemente establecí el tema en holo e inflaron un menú en onCreateOptionsMenu ... y apareció la barra de acciones ... seguí el tutorial de Android ActionBar de http://developer.android.com/guide/topics/ui/actionbar.html. Soy sory si me he perdido algo, ya que soy nuevo en Android – Aamir

Cuestiones relacionadas