2011-12-21 8 views
1

xmlファイルのリストビューでいくつかのビューを作成しています。 そのリストビューでは、私はリストセレクタ属性を持っていて、セレクタのdrawable イメージを定義しました。リストビューlistselectorが機能しない

私のxmlファイルは次のように次の:

<?xml version="1.0" encoding="utf-8"?> 
     <FrameLayout android:id="@+id/frameLayout1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      xmlns:android="http://schemas.android.com/apk/res/android"> 
      <com.naaima.vovinet.activity.VideoNativePlayer 
        android:layout_marginLeft="50dip" 
        android:layout_width="800dip" 
        android:layout_marginRight="30dip" 
        android:id="@+id/video_view" 
        android:layout_height="600dip" 
        android:layout_marginTop="50dip"> 
       </com.naaima.vovinet.activity.VideoNativePlayer> 
      <ImageView android:src="@drawable/icon" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:id="@+id/imageView1"/> 
      <ImageView android:src="@drawable/icon" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:layout_gravity="center_horizontal" 
       android:id="@+id/imageView2"/> 

      <LinearLayout android:id="@+id/linearlayout" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 

      <TextView 
        android:id="@+id/textView_channelno" 
        android:layout_width="130dip" 
        android:hint="_ _ _" 
        android:layout_marginLeft="1050dip" 
        android:layout_marginTop="20dip" 
        android:background="@drawable/sample" 
        android:gravity="center" 
        android:textSize="25dip" 
        android:visibility="gone" 
        android:layout_height="80dip"/> 


       </LinearLayout> 



      <FrameLayout android:id="@+id/frameLayout2" 
       android:layout_width="1100dip" 
       android:layout_height="wrap_content" 
       android:background="@drawable/bg1" 
       android:layout_gravity="bottom" 
       android:layout_marginLeft="100dip" 
       android:layout_marginBottom="15dip"> 



       <RelativeLayout android:id="@+id/relativeLayout1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"> 
         <ProgressBar style="?android:attr/progressBarStyleHorizontal" 
          android:layout_width="730dip" 
          android:layout_height="wrap_content" 
          android:id="@+id/progressBar" 
          android:layout_marginTop="30dip" 
          android:background="@drawable/progress_bar_bg" 
          android:layout_marginLeft="180dip"/> 

         <TextView android:id="@+id/textView_date" 
          android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
          android:layout_toRightOf="@+id/progressBar" 
          android:layout_marginTop="30dip" 
          android:layout_marginLeft="50dip"/> 

         <TextView android:id="@+id/textView_time" 
          android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
          android:layout_below="@+id/textView_date" 
          android:layout_marginTop="3dip" 
          android:layout_toRightOf="@+id/list" 
          android:layout_marginLeft="57dip" 
          /> 

        <TextView 
          android:id="@+id/textView_location" 
          android:text="Hyderabad" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_below="@+id/textView_time" 
          android:layout_marginTop="10dip" 
          android:layout_marginRight="10dip" 
          android:layout_toRightOf="@+id/imageView_temp" 
          /> 

          <TextView 
          android:id="@+id/textView_temp" 
          android:text="35 Degrees" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_below="@+id/textView_location" 
          android:layout_marginRight="10dip" 
          android:layout_marginTop="5dip" 
          android:layout_toRightOf="@+id/imageView_temp" 
          /> 

         <ImageView android:id="@+id/imageView_temp" 
          android:src="@drawable/temp" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_below="@+id/textView_time" 
          android:layout_toRightOf="@+id/list" 
          android:layout_marginLeft="20dip"/> 

        <ImageView android:id="@+id/imageView_logo" 
          android:src="@drawable/zee" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginTop="30dip" 
          android:layout_marginLeft="50dip"/> 


         <ImageView android:id="@+id/imageView_left" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:src="@drawable/arrow_left_gray" 
          android:layout_marginTop="110dip" 
          android:layout_marginLeft="23dip"/> 

         <TextView android:id="@+id/txt_channelName" 
          android:text="M-Tunes" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginTop="110dip" 
          android:layout_marginLeft="50dip"/> 

         <ImageView android:id="@+id/imageView_right" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:src="@drawable/arrow_right_gray" 
          android:layout_marginTop="110dip" 
          android:layout_marginLeft="150dip"/> 

         <ListView android:id="@+id/list" 
          android:layout_width="690dip" 
          android:layout_height="125dip" 
          android:layout_below="@+id/progressBar" 
          android:layout_marginLeft="220dip" 
              android:listSelector="@drawable/highlight_bar"/> 
           <ImageView android:id="@+id/imageView_up" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:src="@drawable/arrow_up_gray" 
          android:layout_below="@+id/progressBar" 
          android:layout_marginTop="5dip" 
          android:layout_marginLeft="180dip"/> 


           </RelativeLayout> 

     </FrameLayout> 

    </FrameLayout>` 

Row.xml

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 
     <TextView android:text="TextView" 
      android:id="@+id/textView_list" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      /> 
    </LinearLayout> 

とJavaコードIが行XMLでのみリストビューを実行していた場合

ListView lv = (ListView) findViewById(R.id.list); 
    String[] values = new String[] { "Now:Harry Potter and Deathly Hellows", "Lord of the Rings:Two Towers", "Lord of the Rings:Return of King", 
        "rd of the Rings:Honneypot solo Dance"}; 

      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
        R.layout.row,R.id.textView_list, values); 
      lv.setAdapter(adapter); 
      lv.setSelector(R.drawable.highlight_bar); 
      lv.setDivider(null); 

を、以下のようなものですコードリストセレクタは正常に動作します。 上下の矢印を押しているとうまくいきます。しかし、私は listviewを上記のコードと統合しています。それはうまくいきません。もし私が上向きに矢印を押しているのであれば、キーボードでは使用しません(リストビュー側には向かない)。

答えて

0

xmlでandroid:focusable = "true"を設定した後で、あなたのコードのlistViewで "requestFocus()"を呼び出してみましたか?ビューからdocs

"特定のビューまたはその子孫の1つにフォーカスを移そうとする場合は、これを呼び出します。フォーカスが合わない場合(isFocusable()がfalseを返す)フォーカスがあり、タッチモード(isFocusableInTouchMode())にフォーカスが当てられません。また、focusSearch(int)も参照してください。これは引数FOCUS_DOWNとnullを指定してrequestFocus(int、Rect)を呼び出すのと同じことです。

+0

ありがとうございました。 – malli

1

Jasonの上記の応答に追加するだけです。私は最近、この問題に遭遇し、Jasonの答えが現れました。ただし、私がリストビューにrequestFocusFromTouch()を呼び出す必要があることを除けば、タッチに対して明らかに反応するようにしました。 requestFocus()はではなく、私のシナリオではが役に立ちましたが、requestFocusFromTouch()は役に立ちました。うまくいけばそれが誰かを助けてくれるでしょう。

関連する問題