2012-12-07 5 views
-3

내가 짝수 행의 배경 색상을 표시하기 위해 다음과 같은 사용자 정의 SimpleCursorAdapter 클래스를 썼다 분실 :의 ListView 안드로이드 기본 애니메이션

public class AlternateRowCursorAdapter extends SimpleCursorAdapter { 

private int[] colors = new int[] { Color.parseColor("#FFFFFF"), 
     Color.parseColor("#EEEEEE") }; 

public AlternateRowCursorAdapter(Context context, int layout, Cursor c, 
     String[] from, int[] to) { 
    super(context, layout, c, from, to); 
} 

@Override 
public void bindView(View view, Context context, Cursor cursor) { 
    super.bindView(view, context, cursor); 

    int colorPos = cursor.getPosition() % colors.length; 
    view.setBackgroundColor(colors[colorPos]); 
} 

} 

그것은 잘 작동하지만 안드로이드 기본 애니메이션 (녹색 배경이에 도청 동안 항목)가 손실됩니다. 기본 애니메이션을 되 찾을 수있는 방법이 있습니까? 미리 감사드립니다.

+1

왜 삭제 중 다시 질문을 게시? http://stackoverflow.com/questions/13693062/custom-simplecursoradapter-without-default-animation – Selvin

답변

0

바보 같은 간단한 솔루션 ...

private int[] colors = new int[] { Color.TRANSPARENT, 
     Color.parseColor("#66EEEEEE") }; 
0

넣고 문

@Override 
public void bindView(View view, Context context, Cursor cursor) { 
    super.bindView(view, context, cursor); 

    if(!selected) { 
    int colorPos = cursor.getPosition() % colors.length; 
    view.setBackgroundColor(colors[colorPos]); 
    } 
} 
0

View의 기본 배경은 좀 더 복잡한 단지 색상보다 경우. Selector과 결합하여 Style입니다. 클릭하면 색상 표시와 같은 여러 이벤트에서 다르게 동작 할 수 있습니다. 또는 다른 색상을 선택했을 때.

자신 만의 배경을 설정하면 이러한 기본 동작을 무시하므로 표시되지 않습니다.

결론 : 여러 동작을 지원하려면 Selector을 사용하십시오.

예 :

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" 
      android:color="#000000" /> <!-- pressed --> 
    <item android:state_focused="true" 
      android:color="#000000" /> <!-- focused --> 
    <item android:color="#FFFFFF" /> <!-- default --> 
</selector>