使用setProgressDrawable了ProgressBar具有自定义颜色不给我们以正确的方式工作.我们在a的行中使用progressbars ListView,但仅当列表中有多个元素时才会显示进度.如果是一个元素,则进度条为空.
CursorAdapter.java:
public class CursorAdapter extends SimpleCursorAdapter {
public CursorAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
}
public void bindView(View view, Context context, Cursor cursor) {
super.bindView(view, context, cursor);
updateProgressbar(view, cursor);
}
/**
* This method updates the progressbar using the "numberpages" and
* "currentpage" values.
*/
private void updateProgressbar(View view, Cursor cursor) {
ProgressBar progressBar = (ProgressBar) view
.findViewById(R.id.progressbarHorizontal);
progressBar.setProgressDrawable(view.getResources().getDrawable(
R.drawable.greenprogress));
progressBar.setMax(cursor.getInt(cursor.getColumnIndex("numberpages")));
progressBar.setProgress(cursor.getInt(cursor
.getColumnIndex("currentpage"))); …Run Code Online (Sandbox Code Playgroud)