【发布时间】:2014-09-18 08:04:39
【问题描述】:
游戏、社区、音乐等在水平列表视图中。
现在社区被选中,社区相关数据如下所示。
我想在点击音乐时突出显示音乐并将社区颜色更改为默认值。
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
((android.widget.LinearLayout)((android.widget.LinearLayout)arg1).getChildAt(2)).setBackgroundColor(getResources().getColor(R.color.MyBlue));
...
这会更改所选项目的背景颜色,但是当我滚动时,其他未选中的项目也会更改。 上面的代码改变了在项目的 xml 文件中定义的线性布局,如下所示。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/IVCategory"
android:layout_width="80dp"
android:layout_height="80dp"
android:contentDescription="@string/app_name"
android:layout_margin="10dp"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/txtCatName"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center"
android:background="@android:color/transparent"
/>
<LinearLayout
android:id="@+id/selectedBlue"
android:layout_width="match_parent"
android:layout_height="3dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
是否有可能以我的方式做到这一点?我搜索了很多,但我不明白选择器如何帮助我。
【问题讨论】:
-
看这篇文章[项目突出显示][1] [1]:stackoverflow.com/questions/16189651/…
标签: android listview selection selecteditem