我正在使用SimpleCursorAdapter将数据库列中的数据绑定到android视图项。 在我的customListView.xml中,我添加了progressbar,我想从我的数据库列中设置此进度条中的maxvalue和进度。
simplecursoradapter的代码:
String[] from = new String[] {category.KEY_NAME};
int[] to = new int[] {R.id.l_category};
adapter = new SimpleCursorAdapter(this,R.layout.customListView,cursor,from,to,0);
adapter.setViewBinder(new CustomViewBinder());
listCategories.setAdapter(adapter);
EDIT。我更改了simplecursoradapter的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/selektor"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="10dp">
<TextView
android:id = "@+id/l_cat"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_weight = "1"
android:text = "NAME"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textSize="20sp" />
<ProgressBar
style="@style/CustomProgressBarHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar4"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp" />
</RelativeLayout>
customListView.xml:
private class MyViewBinder implements SimpleCursorAdapter.ViewBinder{
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(view.getId()==R.id.progressBar4)
{
ProgressBar progress = (ProgressBar) view;
progress.setMax(cursor.getColumnIndex("MAX"));
progress.setProgress(cursor.getColumnIndex("PROGRESS"));
return true;
}
return false;
}
}
EDIT。添加了ViewBinder类。 我曾尝试使用SimpleCursorAdapter.ViewBinder,但我不知道它没有设置我的进度条值的错误。
这就是我实现ViewBinder的方式:
select