1

I have ListView with progressBar(I make it vertical) in every item, than I change color of progressBar in getView() method of my CustomCursorAdapter :

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));

,but when I scroll up/down the progress of progressBar is dissapear, I need some how redraw the bar, how? My CustomAdapter code :

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;

    }
}

what to do? Thank you !! p.s. similar problem with checkBoxes I have solved using boolean array;

4

0 回答 0