Android ListView中进度条的动态颜色更改

Android ListView中进度条的动态颜色更改,android,android-listview,android-progressbar,Android,Android Listview,Android Progressbar,我让带有progressBarI的ListView在每个项目中保持垂直,然后在CustomCursorAdapter的getView方法中更改progressBar的颜色: String MyColor = "#FFFFffff"; final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 }; ShapeDrawable pgDrawable = new ShapeDrawable(n

我让带有progressBarI的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的进度不稳定时,我需要了解如何重新绘制进度条,如何? 我的自定义适配器代码:

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;

    }
}
怎么办? 非常感谢。 p、 我用布尔数组解决了复选框的类似问题