I have an xml layout which I use for each row in my listview:
<TextView
android:id="@+id/bar"
android:layout_width="fill_parent"
android:layout_height="20dip"
android:layout_marginTop="10dip"
android:layout_below="@+id/user_name"
android:background="@drawable/userchallenge_layout_border"/>
<TextView
android:id="@+id/bar_reached"
android:layout_width="wrap_content"
android:layout_height="20dip"
android:layout_marginTop="10dip"
android:layout_below="@+id/user_name"
android:background="@drawable/userchallenge_layout_border_progress"/>
The background is a drawable I made myself in an xml file, with color, strokes and such.
I have a list of users in my listview, and each user has a value, and I want to draw the as a progress how far each user has reached in the challenge. This is how I calculate it and draw it in my listview:
TextView userName = (TextView) v.findViewById(R.id.user_name);
userName.setTypeface(tf);
userName.setText(uc.getUser().getFullName());
TextView totalBar = (TextView) v.findViewById(R.id.bar);
final int totalBarWidth = totalBar.getWidth();
TextView percent = (TextView) v.findViewById(R.id.percent);
percent.setTypeface(tf);
percent.setText(oneDigit.format((uc.getValue()/challenge.getGoal()) * 100) + " %");
TextView reachedBar = (TextView) v.findViewById(R.id.bar_reached);
reachedBar.setWidth((int) ((uc.getValue()/challenge.getGoal()) * totalBarWidth));
I get the right calculation, but my TextView (bar_reached) sometimes sets the width and sometimes it doesn’t, I know that listviews redraws each time for each row, but I don’t know how to solve this problem!
Please help
You need to make a
List<Float> progressListof progress and load data from itprogressList.get(position)when getView(int position, View convertView, ViewGroup parent) method is called . When progress changed save itprogressList.get(position) = newProgressBy the way why just not to use ProgressBar?