2009-11-19 89 views
1

我有一個佈局,其中有一個按鈕,後面跟着一個ListView。我遇到的問題是當按鈕有焦點(背景爲橙色),並且我在我的鍵盤上按下DOWN時,ListView的第一行沒有焦點。將焦點從按鈕移動到ListView時出現問題

 <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

      <ImageButton android:id="@+id/button" style="@android:style/Button"/> 

    </LinearLayout> 

    <ListView android:id="@+id/action_list" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
     /> 

這是每行的ListView控件的佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:focusable="true" 
><TextView android:id="@+id/text1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

    /> 
</LinearLayout> 

我已經使用 '機器人:nextFocusDown' 嘗試屬性,但是這並不能幫助我的問題:

  <ImageButton android:id="@+id/button" style="@android:style/Button"/> 

    </LinearLayout> 

    <ListView android:id="@+id/action_list" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:nextFocusUp="@id/button" 
     /> 

任何想法如何解決這個焦點問題?當我按DOWN時,我基本上想要將焦點移動到ListView的第一行。當我按下UP時,ListView的第一行將焦點移動到按鈕上。

謝謝。

回答

0

我有同樣的問題,谷歌試圖找到一種方法來做到這一點,但我只是tryed的list_view方法和我的固定是這樣的:

ListView list_view = getListView(); 
list_view.requestFocus(); 
list_view.setSelection(0); 

你必須將焦點設置在列表視圖中,但如果你想出現聚焦某個項目,你必須調用你想要選擇的索引項目的setSelection方法。

0

你試穿focusChangeListener

請試試吧。而那個聽衆的按鈕,雖然它得到改變,把代碼專注於ListView

e.g. yourListView.requetFocus(); 

讓我知道是否有任何查詢。