0
내 서랍 레이아웃 :안드로이드 - 사용자 정의 어댑터가 팽창 할 때 서랍 메뉴 목록 항목 클릭에 색상을 변경하지 않습니다
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<!-- The navigation drawer -->
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:divider="@android:color/darker_gray"
android:dividerHeight="0.1dp"
android:listSelector="@drawable/drawer_list_selector"
/>
</android.support.v4.widget.DrawerLayout>
내 목록 행 : 다음
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/drawer_list_item_image"
android:contentDescription="Menu item image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_gravity="center_vertical"
/>
<TextView
android:id="@+id/drawer_list_item"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:textColor="@android:color/black"
/>
</LinearLayout>
내 사용자 지정에서의 getView 방법 어댑터 :
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View drawerRow = inflater.inflate(R.layout.drawer_row, parent, false);
TextView drawerRowText = (TextView) drawerRow
.findViewById(R.id.drawer_list_item);
ImageView drawerRowImage = (ImageView) drawerRow
.findViewById(R.id.drawer_list_item_image);
drawerRowText.setText(drawerRowTextValues[position]);
switch (position) {
case 0:
drawerRowImage.setImageResource(R.drawable.content_new_dark);
break;
case 1:
drawerRowImage.setImageResource(R.drawable.location_web_site_dark);
break;
case 2:
drawerRowImage.setImageResource(R.drawable.action_settings_dark);
break;
}
drawerRow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("drawer list item clicked...");
}
});
return drawerRow;
}
이벤트가 발생했음을 확인할 수 있습니다. 목록 항목 색상이 깜박이는 것을 확인할 수 없습니다. k 예를 들어 ArrayAdapter를 사용하는 경우와 반대입니다.
아이디어가 있으십니까?
편집 :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- pressed state. -->
<item android:drawable="@color/list_row_pressed_bg"
android:state_pressed="true"/>
</selector>
을 ... 다음 줄에 위의 listSelector 나의 목록보기에 추가 :
android:listSelector="@drawable/drawer_list_selector"
다음과 같이 OK, 나는 listSelector을 추가하여 거의 원하는 동작을 얻었다
지금 내 유일한 문제는 눌려진 상태의 색이 목록의 전체 항목 행을 채우지 않는다는 것입니다.
하지만 난 당신이 색상을 변경 표시되지 않습니다. onClick은 메시지 인쇄 이외의 작업을 수행하지 않습니다 ... ?? –
ArrayAdapter를 사용할 때도 마찬가지입니다. ArrayAdapter를 사용할 때 정확히 동일한 TextView가 있지만 클릭 할 때 목록 항목이 깜박입니다. –
"깜박"또는 간단히 선택하여 표시합니까? 어쩌면 기본 ListView 선택기가 표시됩니까? (http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:listSelector) –