我使用的是ExpandableListActivity
,底部有一個ProgressBar來確定檢查了多少行。當活動開始時,ProgressBar的進度無法正常工作
活動的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/activity_main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100" >
<include
android:id="@+id/activity_checklist_titlebar"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="10"
layout="@layout/titlebar" />
<ExpandableListView
android:id="@+id/android:list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="90" >
</ExpandableListView>
</LinearLayout>
<ProgressBar
android:id="@+id/activity_checklist_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="@dimen/height_activity_checklist_progress"
android:layout_alignParentBottom="true" />
<TextView
android:id="@+id/activity_checklist_progress_text"
style="@style/Text.Strong.Medium"
android:layout_width="wrap_content"
android:layout_height="@dimen/height_activity_checklist_progress"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="0/50" />
</RelativeLayout>
我在這裏更新進度:
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
{
// ...
TextView overall_progress_text =
(TextView) main_layout.findViewById(R.id.activity_checklist_progress_text);
int overall_progress = checklist.getProgress();
overall_progress_text.setText(overall_progress + "/" + checklist.size());
ProgressBar overall_progress_bar =
(ProgressBar) main_layout.findViewById(R.id.activity_checklist_progress);
overall_progress_bar.setProgress(overall_progress);
overall_progress_bar.setMax(checklist.size());
return convertView;
}
正如你可以看到我有一個TextView顯示進度過了,顯然價值的罰款。當我開始更改列表中複選框的狀態時,一切正常,唯一的問題是在活動開始時。
進度條顯示了這個(我認爲最大價值正在採取「100」,而不是「9」):