wenjun12369 2012-01-05 22:43
浏览 273
已采纳

listview 获得焦点 item背景图片变化

[b][/b]我需要的是item选中时,item的背景图片切换。但是实现不了。

这是listview xml

<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

android:id="@+id/list_id"
android:layout_weight="1"
android:paddingTop="40dp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:listSelector="@drawable/list_picture"
android:focusable="true"
/>

内部条目的xml

<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/item3" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#545454"
android:textSize="25px"
android:textStyle="bold"
android:id="@+id/first"/>

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#545454"
android:id="@+id/second"/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FF0000"
android:id="@+id/third"/>

切换图片的xml

<?xml version="1.0" encoding="utf-8" ?>

android:state_window_focused="false"
android:drawable="@drawable/item3" />
android:state_pressed="true"
android:drawable="@drawable/itemchange" />
android:state_pressed="true"
android:drawable="@drawable/itemchange" />
android:drawable="@drawable/itemchange" />
android:drawable="@drawable/itemchange" />

在Activity中如果是
[b]listview= new listview(this);就不会报错 但这样不能获取listview 的id;
listview=(listview)findViewById(R.id.list_id);就会报错,nullpointerexception;[/b]

开始时没有考虑item换背景的问题,所以没有listview xml文件,现在想把橙黄色背景换成图片。却出现错误。

在没有继承listActivity时,取id报错,要是继承listActivity时,item全部不见了,只剩下addfooter的添加内容。

求解释·········求解决

  • 写回答

3条回答 默认 最新

  • laopeng301 2012-01-06 10:21
    关注

    [code="java"] android:drawable="@drawable/没有焦点时的图片背景" />

    你检查下 你的这个图片。
    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型