android 显示数字,android – 在ProgressBar中显示数字

我有一个ProgressBar.

它工作正常,但我需要显示最大值和当前值.

他们不在那里.

我需要更改为ProgressDialog吗?

澄清:

我正在展示ProgressBar.

酒吧出现完美,但我希望数字也出现.

因此,例如,最大值为1000,当前点为300,然后我想要1000出现,栏的结尾和300出现在栏上或其下方.

我使用此类作为List Adapter来填充ListView.

显示的行取决于“奖励”数组中的数据类型.

在执行ProgressBar时,它显示没有数字.

码:

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

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

}

}

布局

android:layout_width="fill_parent"

android:layout_height="wrap_content">

android:typeface="sans"

android:textSize="14sp"

android:textStyle="italic"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

android:typeface="sans"

android:textSize="14sp"

android:textStyle="italic"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/tvwShortMessage"/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginBottom="15dp"

android:layout_below="@id/tvwLongMessage">

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"/>

这是最后一个屏幕.

它是迄今为止一系列任务及其进展的列表.

每个“行”都是一个单独的进度条.

解决方法:

为什么不手动添加文本,这似乎是一个非常简单的方法,我把它放在我想要的地方,但你可以根据需要改变布局.

对不起,如果代码中有任何错误,我没有运行它.

XML:

android:layout_width="fill_parent"

android:layout_height="wrap_content">

android:typeface="sans"

android:textSize="14sp"

android:textStyle="italic"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

android:typeface="sans"

android:textSize="14sp"

android:textStyle="italic"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/tvwShortMessage"/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginBottom="15dp"

android:layout_below="@id/tvwLongMessage">

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"/>

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"/>

类:

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;

}

}

标签:android,progressdialog,progress-bar

来源: https://codeday.me/bug/20191002/1843442.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值