我有一个ProgressBar.
它工作正常,但我需要显示最大值和当前值.
他们不在那里.
我需要更改为ProgressDialog吗?
澄清:
我正在展示ProgressBar.
酒吧出现完美,但我希望数字也出现.
因此,例如,最大值为1000,当前点为300,然后我想要1000出现,栏的结尾和300出现在栏上或其下方.
我使用此类作为List Adapter来填充ListView.
显示的行取决于“奖励”数组中的数据类型.
在执行ProgressBar时,它显示没有数字.
码:
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>
这是最后一个屏幕.
它是迄今为止一系列任务及其进展的列表.
每个“行”都是一个单独的进度条.
解决方法:
为什么不手动添加文本,这似乎是一个非常简单的方法,我把它放在我想要的地方,但你可以根据需要改变布局.
对不起,如果代码中有任何错误,我没有运行它.
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;
}
}