Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将复选框替换为星形图像,以在Android应用程序中强调它_Android_Android Layout_Android Intent_Android Fragments_Android Listview - Fatal编程技术网

将复选框替换为星形图像,以在Android应用程序中强调它

将复选框替换为星形图像,以在Android应用程序中强调它,android,android-layout,android-intent,android-fragments,android-listview,Android,Android Layout,Android Intent,Android Fragments,Android Listview,我在Android应用程序中有一个列表视图页面,其中每一行都包含/显示文本、日期和复选框 如果选中了复选框,则表示列表中的特定行很重要。 现在我想用星图替换复选框,以指示行是重要的。列表页面代码如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="

我在Android应用程序中有一个列表视图页面,其中每一行都包含/显示文本、日期和复选框

如果选中了复选框,则表示列表中的特定行很重要。 现在我想用星图替换复选框,以指示行是重要的。列表页面代码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@drawable/background_activated">

  <CheckBox android:id="@+id/note_list_item_solvedCheckBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_alignParentRight="true"
    android:enabled="false"
    android:focusable="false"
    android:padding="4dp" />

  <TextView android:id="@+id/note_list_item_titleTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/note_list_item_solvedCheckBox"
    android:textStyle="bold"
    android:paddingLeft="4dp"
    android:paddingRight="4dp"
    android:text="Note title" />

  <TextView android:id="@+id/note_list_item_dateTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/note_list_item_titleTextView"
    android:layout_toLeftOf="@id/note_list_item_solvedCheckBox"
    android:paddingLeft="4dp"
    android:paddingRight="4dp"
    android:paddingTop="4dp"
    />


</RelativeLayout>


有人能给我用我的星图替换复选框的代码吗?

您必须为此编写自己的自定义控件类,并在布局文件中使用相同的代码替换复选框

或者,只需在您的可绘制文件夹中设置两个图像star_unactive和star_active,并将它们与图像视图关联即可。您必须在适配器类中实现切换逻辑


将listView行布局文件中的“复选框”替换为“ImageView”。将侦听器设置为此ImageView。对其执行开关逻辑。当切换到“设置星光活动图像”或“设置星光非活动图像”时。

幸运的是,我刚刚做了这个,在drawable中创建一个选择器,如下所示:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
    android:drawable="@drawable/star_checked" />
<item android:state_pressed="true"
    android:drawable="@drawable/star_checked" />
<item android:drawable="@drawable/star_unchecked" />
</selector>
<CheckBox
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/checkBoxFavourite"
   android:button="@drawable/selector_checkbox" <!-- this is the important line -->
   android:gravity="center"
   android:layout_marginLeft="10dp"
   android:focusable="false"
   android:focusableInTouchMode="false"/>