2011-12-21 271 views
1

我在我的xml文件xml文件contaings列表视图中创建了一些视图。 在该列表视图中我有列表选择器属性,并且我定义了可选择的 图片。Listview listselector not working

我的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代码就像如果我只执行列表视图与行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); 

代码列表选择工作正常。 如果我按上下箭头它工作正常。但我正在整合 列表视图与上面的代码它不工作,如果我按下键盘箭头 没有用(重点不会去列表视图方面)。

回答

0

在xml中设置android:focusable =“true”之后,您是否尝试过在代码中的listView上调用“requestFocus()”?从视图docs

“调用此方法可尝试将焦点放在特定的视图或其某个后代上。如果视图不可聚焦(isFocusable()返回false),则视图实际上不会获得焦点,或者如果它是可以聚焦的,并且当设备处于触摸模式时,它不能在触摸模式(isFocusableInTouchMode())下聚焦。另请参见focusSearch(int),这是您打电话表示您有焦点并且您希望父母看起来对于下一个,这相当于使用参数FOCUS_DOWN和null调用requestFocus(int,Rect)。“

+0

感谢您的帮助。现在工作正常。 – malli 2011-12-21 16:00:29

1

只是为了增加Jason的上述响应。我最近遇到了这个问题,贾森的答案是现货,除了我需要在我的listView上调用requestFocusFromTouch(),使其显然适用于触摸。 requestFocus()是不是有助于我的方案,但requestFocusFromTouch()是。希望能帮助那里的人。