2012-02-11 13 views
5

Sto sviluppando un'applicazione per Google TV in cui tutta la navigazione verrà eseguita utilizzando D-Pad/Tastiera.Come impostare programmaticamente il prossimo controllo attivo di ActionBar su Android

La mia attività ha una barra delle azioni e alcuni elenchi in orizzontale sotto di essa. dire lista A, B & C. Elenchi B & C caricare i dati in base alla voce selezionata nell'elenco A .. in modo che possano/non caricare i dati.

problemi è che quando ActionBar è stato attivato e premo il tasto DOWN D-Pad, l'attenzione è persa e non è trasferito to List C (o B se C non ha dati) .. y?

Per raggiungere questo obiettivo, ho cercato di impostare la prossima vista attivabile del ActionBar programmaticamente come seguire

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

, ma non ha funzionato.

Ho anche provato a controllare la gerarchia del layout utilizzando Hierarchy Viewer ... ma, francamente, non ho capito cosa fare con i suoi risultati.

Come posso impostare programmaticamente il successivo controllo di messa a fuoco di Android ActionBar ??

Qualsiasi aiuto è molto apprezzato.

XML di attività è la seguente:

<?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> 

Tutti i contenitori di ciascuna lista/Android griglia fino I più LinearLayout hanno fissato: attivabile = "true" direttamente o nel suo stile.

EDIT: applicazione di esempio che descrive esattamente lo schermo del mio spp può essere scaricato dal here

Si prega di includere nel primo elenco. Puoi cercarlo dal suo id allPackagesList nel file main.xml. Ho dimenticato di inserirlo. dispiace

Issues in questa applicazione sono:

  1. messa a fuoco non viene a elenco/griglie da ActionBar voce.
  2. navigazione tra ActionBar articoli richiede più di un D-pad "sinistra" o "DESTRA" presse per spostare

risposta

0

l'elenco avvolto all'interno di un altro contenitore? Prova ad aggiungere android: focusable = "true" per le tue liste e i loro contenitori ..

+0

non ha funzionato ... ho aggiornato la mia domanda e inserito l'XML dell'attività .. posso usare qualche intestazione personalizzata con pulsanti (per agire come pulsanti di azione) e l'immagine per un logo .. ma io non voglio ... come voglio usare l'ActionBar integrato. Per favore aiutami a risolverlo perché è molto urgente – Aamir

+0

Non vedo ListView o ActionBar nel xml. –

+0

ListView e due GridView ci sono in xml ... e non ho aggiunto ActionBar in XML ... ho appena impostato il tema su holo e ho gonfiato un menu in onCreateOptionsMenu .. e l'ActionBar è apparso ... ho seguito il tutorial di Android ActionBar da http://developer.android.com/guide/topics/ui/actionbar.html. Sono Sory se ho perso qualcosa come io sono nuovo per Android – Aamir