Show numbers in ProgressBar

后端 未结 4 1015
谎友^
谎友^ 2020-12-20 16:59

I have a ProgressBar. It works ok but I need to show the max value and the current value. They are not there.

Do I need to change to a ProgressDialog?

Clarif

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-20 17:37

    Why dont you just add the text manually, it seems like a much simple approach, I placed it where ever I wanted here, but you can just change the layout to what your need are.

    Sorry if there are any mistakes in the code, I didnt run this.

    XML:

    
    
    
    
    
    
    
    
    

    Class:

    private class AwardsAdapter extends ArrayAdapter {
    
    
        private ArrayList awards = new ArrayList();
    
        public AwardsAdapter(Context context, int textViewResourceId, ArrayList 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;
        }
    
    }
    

提交回复
热议问题