게임, 커뮤니티, 음악 등은 가로 목록보기입니다.
지금 커뮤니티가 선택되었으며 커뮤니티와 관련된 데이터가 아래에 나와 있습니다.
클릭하면 음악을 강조 표시하고 커뮤니티 색상을 기본값으로 변경하고 싶습니다.
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] : http://stackoverflow.com/questions/16189651/android-listview-selected-item-stay-highlighted – FreshD