gpt4 book ai didi

android - ListView 列表选择器不工作

转载 作者:行者123 更新时间:2023-11-30 04:25:41 27 4
gpt4 key购买 nike

我正在我的 xml 文件中创建一些 View ,xml 文件包含 ListView 。在那个 ListView 中,我有列表选择器属性,我定义了 drawable选择器的图像。

我的 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>`

行.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代码如下

    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);

如果我只执行带有行 xml 代码列表选择器的 ListView ,则工作正常。如果我按向上和向下箭头,它工作正常。但我正在整合上面代码的 ListView 不起作用,如果我按下向上键和箭头在键盘上没有用(重点不在 ListView 端)。

最佳答案

只是为了补充 Jason 的上述回复。我最近遇到了这个问题,Jason 的回答很准确,只是我需要在我的 listView 上调用 requestFocusFromTouch() 以使其响应明显的触摸。 requestFocus() 在我的场景中没有帮助,但 requestFocusFromTouch() 有用。希望这可以帮助那里的人。

关于android - ListView 列表选择器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8589448/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com