Show rooms at ProgressBar

I have a ProgressBar. It works fine, but I need to show the maximum value and the current value. They are not there.

Do I need to upgrade to ProgressDialog?

Clarification:

I am showing a ProgressBar. The bar is perfect, but I want the rooms to be displayed as well. So, for example, this is max 1000, the current point is 300, then I want 1000 to appear, and the end of the bar and 300 appear somewhere in the panel or a little lower.

I use this class as a List Adapter to populate a ListView. The displayed string depends on the type of data in the reward array. When the ProgressBar is executed, it appears without numbers.

the code:

private class AwardsAdapter extends ArrayAdapter <AwardItem>{ private ArrayList<AwardItem> awards = new ArrayList<AwardItem>(); public AwardsAdapter(Context context, int textViewResourceId, ArrayList<AwardItem> awards) { super(context, textViewResourceId,awards); this.awards = awards; // TODO Auto-generated constructor stub } public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater)AwardsActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.awards_row, parent, false); } AwardItem award = awards.get(position); ProgressBar pb = (ProgressBar) v.findViewById(R.id.pgbAwardProgress); if(award.award_type == PROGRESSIVE) { pb.setVisibility(View.VISIBLE); pb.setMax(award.requirement); pb.setProgress(award.current_amount); pb.setIndeterminate(false); } else { pb.setVisibility(View.GONE); } ((TextView) v.findViewById(R.id.tvwShortMessage)). setText(MessageBuilder.buildMessage(AwardsActivity.this, award.award_text, Integer.valueOf(award.requirement).toString())); return v; } } 

Markup

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tvwShortMessage" android:typeface="sans" android:textSize="14sp" android:textStyle="italic" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/tvwLongMessage" android:typeface="sans" android:textSize="14sp" android:textStyle="italic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/tvwShortMessage"/> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="15dp" android:layout_below="@id/tvwLongMessage"> <ProgressBar android:id="@+id/pgbAwardProgress" android:layout_width="fill_parent" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:layout_marginBottom="15dp" android:layout_alignParentTop="true"/> </LinearLayout> </RelativeLayout> 

This is the last screen. This is a list of tasks and their progress. Each "line" is a separate indicator of progress.

enter image description here

+7
source share
4 answers

Why don’t you just add the text manually, this seems like a very simple approach, I put it where I want, but you can just change the layout to what you need.

Sorry if there are any errors in the code, I did not run this.

XML:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tvwShortMessage" android:typeface="sans" android:textSize="14sp" android:textStyle="italic" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/tvwLongMessage" android:typeface="sans" android:textSize="14sp" android:textStyle="italic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/tvwShortMessage"/> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="15dp" android:layout_below="@id/tvwLongMessage"> <ProgressBar android:id="@+id/pgbAwardProgress" android:layout_width="fill_parent" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:layout_marginBottom="15dp" android:layout_alignParentTop="true"/> </LinearLayout> <TextView android:id="@+id/pgbAwardProgressText" android:typeface="sans" android:textSize="14sp" android:textStyle="italic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/pgbAwardProgress" android:layout_alignParentRight="true" android:visibility="gone"/> </RelativeLayout> 

Grade:

 private class AwardsAdapter extends ArrayAdapter <AwardItem>{ private ArrayList<AwardItem> awards = new ArrayList<AwardItem>(); public AwardsAdapter(Context context, int textViewResourceId, ArrayList<AwardItem> awards) { super(context, textViewResourceId,awards); this.awards = awards; // TODO Auto-generated constructor stub } public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater)AwardsActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.awards_row, parent, false); } AwardItem award = awards.get(position); ProgressBar pb = (ProgressBar) v.findViewById(R.id.pgbAwardProgress); if(award.award_type == PROGRESSIVE) { pb.setVisibility(View.VISIBLE); pb.setMax(award.requirement); pb.setProgress(award.current_amount); pb.setIndeterminate(false); TextView progressText = ((TextView) v.findViewById(R.id.pgbAwardProgressText)); progressText.setVisibility(View.VISIBLE); progressText.setText(award.current_amount+"/"+award.requirement); } else { pb.setVisibility(View.GONE); } ((TextView) v.findViewById(R.id.tvwShortMessage)). setText(MessageBuilder.buildMessage(AwardsActivity.this, award.award_text, Integer.valueOf(award.requirement).toString())); return v; } } 
+3
source

ProgressBar disabled to show progress. You will find a good tutorial here to show your progress. It is recommended that you use AsyncTask to update Progress because it is a painless streaming experience.

Basic AsyncTask with a progress bar widget

+3
source

New NumberProgressBar library:

Number progress bar

Check out this awesome NumberProgressBar library on Github with many other color styles.

enter image description here

Credits: Mr. Daimajia,

According to him, NumberProgressBar is a bar, thin and sexy (everyone wants it!).

+3
source

I do not think you want to use progressbar. It looks like a SeekBar with some numbers on both ends.

 <LinearLayout android:id="@+id/LinearLayout_Lose250HandsSlider" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/TextView_MinValue" android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="0"/> <SeekBar android:id="@+id/SeekBar_Lose250HandsSlider" android:max="250" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1.0"/> <TextView android:id="@+id/TextView_CurrentValue" android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="250"/> </LinearLayout> 
0
source

All Articles