Android progress bar in list always vague

I am trying to set a fixed progress in items in a ListView. I only see an indefinite rotating circle in the ListView ... what am I doing wrong? (I'm sure the answer is simple ... I just don't see it)

For the following xml adapter layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/some_text" android:layout_width="match_parent" android:layout_height="wrap_content" /> <ProgressBar android:id="@+id/some_progress" android:layout_width="match_parent" android:layout_height="wrap_content" /> 

the code:

 public class SomeListAdapter extends ArrayAdapter<MyItem> { private static class ViewHolder { TextView nameTextView; ProgressBar valueProgressBar; } public BestChoiceListAdapter(Context context, List<MyItem> items) { super(context, R.layout.list_item, items); } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; View view = convertView; if (view == null) { LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = vi.inflate(R.layout.list_item, null); holder = new ViewHolder(); holder.nameTextView = (TextView) view.findViewById(R.id.some_text); holder.valueProgressBar = (ProgressBar) view.findViewById(R.id.some_progress); view.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } MyItem optionItem = getItem(position); holder.nameTextView.setText(optionItem.getOptionName()); int progress = (int) (optionItem.getOptionValue()); holder.valueProgressBar.setProgress(progress); return view; } } 
+8
android
source share
2 answers

The easiest way is to apply a horizontal style to it:

 <ProgressBar android:id="@+id/some_progress" style="@android:style/Widget.ProgressBar.Horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" /> 

This will create all the attributes that you will need to add manually in order to apply a specific runtime.

If you're interested, here is what this system style looks like if you want to apply properties individually:

 <style name="Widget.ProgressBar.Horizontal"> <item name="android:indeterminateOnly">false</item> <item name="android:progressDrawable">@android:drawable/progress_horizontal</item> <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item> <item name="android:minHeight">20dip</item> <item name="android:maxHeight">20dip</item> </style> 

NTN

+12
source share

Change the undefined mode to false!

 <ProgressBar  android:id="@+id/some_progress" android:layout_width="match_parent" android:layout_height="wrap_content" android:indeterminate="false" /> 
0
source share

All Articles