【发布时间】:2014-01-05 19:49:31
【问题描述】:
我有一个包含按钮的列表视图和一个文本视图,该文本视图被正常点击;但是我有一个按钮单击的方法,当单击按钮时,它应该更改背景图像,因此通过单击按钮,按钮的所有实例都在更改背景图像,因此我单击列表视图中的 fiew 按钮和我向下滚动,我看到几个按钮的背景图像发生了变化,而不是按钮的位置发生了变化,同时再次向上滚动列表视图; 我该如何解决?
我的listview内容的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/bt_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:background="@android:drawable/btn_star_big_off"
android:onClick="myClickHandler"/>
<TextView
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/fsinlistview"
/>
</LinearLayout>
我的按钮点击代码是:
public void myClickHandler(View v)
{
Button button = (Button)v.findViewById(R.id.bt_rating);
button.setBackgroundResource(android.R.drawable.btn_star_big_on);
}
【问题讨论】:
-
myClickHandler方法的代码是什么样的?