我在每个项目中都有带有progressBar的ListView(我使它垂直),而不是我在CustomCursorAdapter的getView()
方法中更改了progressBar的颜色:
String MyColor = "#FFFFffff";
final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
ShapeDrawable pgDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null));
pgDrawable.getPaint().setColor(Color.parseColor(MyColor));
ClipDrawable progress = new ClipDrawable(pgDrawable, Gravity.BOTTOM, ClipDrawable.VERTICAL);
itemRow.vProgressBar.setProgressDrawable(progress);
itemRow.vProgressBar.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.vertical_progress_bar));
,但是当我向上/向下滚动progressBar的进度消失时,我需要一些如何重绘条,怎么样? 我的CustomAdapter代码:
public class CustomAdapter extends SimpleCursorAdapter {
private Cursor cursor;
private Activity context;
private int layout;
private ListItemRow itemRow;
private LayoutInflater layoutInflater;
private boolean[] checkBoxStates;
private byte[] progressValues;
int listItemCounter;
public CustomAdapter(Activity context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
this.context = context;
this.layout = layout;
this.cursor = c;
checkBoxStates = new boolean[cursor.getCount()];
progressValues = new byte[cursor.getCount()];
int guess,fail;
cursor.moveToFirst();
for(int i=0;i<cursor.getCount();i++)
{
checkBoxStates[i] = Boolean.valueOf(cursor.getString(4));
guess = cursor.getInt(5);
fail = cursor.getInt(6);
if(guess != 0)
progressValues[i] = (byte)(100.0/(double)((double)(guess+fail)/(double)guess));
else
progressValues[i] = 0;
cursor.moveToNext();
}
cursor.moveToFirst();
listItemCounter = 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
listItemCounter = position;
View rowView = convertView;
if (rowView == null) {
itemRow = new ListItemRow();
layoutInflater = context.getLayoutInflater();
rowView = layoutInflater.inflate(layout, null, false);
itemRow.starChek = (CheckBox) rowView.findViewById(R.id.starCheck);
itemRow.textViewWord = (TextView) rowView
.findViewById(R.id.textViewWord);
itemRow.textViewTranslate = (TextView) rowView
.findViewById(R.id.textViewTranslate);
itemRow.textViewSuccessPoints = (TextView) rowView
.findViewById(R.id.textViewSuccessPoints);
itemRow.vProgressBar = (ProgressBar) rowView
.findViewById(R.id.vertical_progressbar);
rowView.setTag(itemRow);
} else {
itemRow = (ListItemRow) rowView.getTag();
}
ListView lv = (ListView) parent;
cursor = (Cursor) lv.getItemAtPosition(position);
itemRow.textViewWord.setText(cursor.getString(1));
itemRow.textViewTranslate.setText(cursor.getString(2));
itemRow.starChek.setTag(cursor.getString(0)); // setTag _id to the star
itemRow.starChek.setChecked(checkBoxStates[position]);
//progress
String MyColor = "#FFFFffff";
final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
ShapeDrawable pgDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null));
pgDrawable.getPaint().setColor(Color.parseColor(MyColor));
ClipDrawable progress = new ClipDrawable(pgDrawable, Gravity.BOTTOM, ClipDrawable.VERTICAL);
itemRow.vProgressBar.setProgressDrawable(progress);
itemRow.vProgressBar.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.vertical_progress_bar));
itemRow.vProgressBar.setProgress(progressValues[position]);
itemRow.starChek.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
MainActivity.dbAdapter.changeValue(v.getTag()
.toString(), null, null, null, String
.valueOf(((CheckBox)v).isChecked()), null, null, null);
if(((CheckBox)v).isChecked())
checkBoxStates[position] = true;
else
checkBoxStates[position] = false;
}
});
return rowView;
}
private class ListItemRow {
public CheckBox starChek;
public TextView textViewWord;
public TextView textViewTranslate;
public TextView textViewSuccessPoints;
public ProgressBar vProgressBar;
}
}
该怎么办? 谢谢 !! 附:我使用布尔数组解决了checkBoxes的类似问题;