在进度条显示的数字 [英] Show numbers in ProgressBar

查看:195
本文介绍了在进度条显示的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个进度条。
它的工作原理确定,但我需要显示的最大值和当前值。
它们不存在。

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

我是否需要更改为ProgressDialog?

Do I need to change to a ProgressDialog?

澄清:

我呈现出进度。
酒吧出现完美,但我想要的数字显示为好。
因此,例如,它的最大是1000当前点为300然后我想1000出现,并在杆的端部300向某处出现在酒吧或略低于它

I am showing a ProgressBar. The bar comes up perfectly but I want the numbers to appear as well. So, for example, it the max is 1000 the current point is 300 then I want 1000 to appear and the end of the bar and 300 to appear somewhere on the bar or just below it.

我使用这个类的列表适配器为ListView控件的填充。
显示该行取决于数据在颁奖阵列的类型。
当执行进度似乎没有数字。

I am using this class as the List Adaptor for the filling of an ListView. The line displayed depends on the type of data in the Array of "awards". When doing a ProgressBar it appears without the numbers.

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

}

布局

<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 final screen. It is a list of a series of tasks and their progress so far. Each "line" is a separate progressbar.

推荐答案

你为什么不只是手动添加文本,这似乎是一个很多简单的方法,我把它放在以往,我想在这里,但你可以改变布局您的需要是什么。

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.

很抱歉,如果有在code任何错误,我没有运行此。

Sorry if there are any mistakes in the code, I didnt 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>

类:

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

}

这篇关于在进度条显示的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆