저는 목록보기를 가지고 있으며 SQLite 데이터베이스에서 검색된 일부 조건에 따라보기 (@+id/panel)
색을 변경하려고합니다. 내가 그렇게 SimpleCursorAdapter.ViewBinder을 사용하고SimpleCursorAdapter.ViewBinder를 사용하여보기의 색을 변경하십시오.
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="10dp"
android:layout_height="fill_parent"
android:layout_weight="0.01"
android:orientation="vertical" >
<View
android:id="@+id/panel"
android:layout_width="10dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#ffa500"
android:layout_marginRight="4dip"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="2.86"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</LinearLayout>
는 :
SimpleCursorAdapter.ViewBinder binder = new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex){
if (view.getId() == R.id.panel)
{
String name = cursor.getString(1);
if (name.equals("Ravi")) {
view.setBackgroundColor(Color.RED);
} else {
view.setBackgroundColor(Color.BLUE);
}
return true;
}
return false;
}
listView.setAdapter(dataAdapter);
dataAdapter.setViewBinder(binder);
이 코드는 여전히 작동하지 않습니다. 코드는 절대로 조건을 통과하지 못합니다. TextView 객체 (@+id/textViewB)
의 글꼴 색상을 변경할 수는 있지만보기 색상을 변경하는 데 성공하지 못했습니다.
답장을 보내 주셔서 감사합니다.
나머지 색과 다른 색을 원한다면 하나의 행만 있습니까? 또는 여러 행? 한 행만 있으면 도움이 될 수 있습니다. –
여러 행은 조건에 따라 다릅니다. 하지만 한 행에 대한 귀하의 솔루션도보고 싶습니다 – neonerdy
왜 SimpleCursorAdapter를 확장하고 대신 getView를 재정의하지 마십시오. –