0

私はを使用してExpandableListActivityおり、下部には、チェックされた行数を決定するための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があり、値は問題ないようです。リスト内のチェックボックスの状態を変更し始めると、すべてが正常に機能します。唯一の問題は、アクティビティの開始時です。

progressBarはこれを示しています(最大値は「9」ではなく「100」を取っていると思います):

ここに画像の説明を入力してください

4

2 に答える 2

2

進行する前に最大値を設定するという問題を解決しただけです。進行直後に最大値を設定してもAndroidのプログレスバーが機能しないようです...

これを変更しました:

overall_progress_bar.setProgress(overall_progress);
overall_progress_bar.setMax(checklist.size());

これに:

overall_progress_bar.setMax(checklist.size());
overall_progress_bar.setProgress(overall_progress);
于 2012-12-01T12:14:46.333 に答える
0

非同期タスクを使用 して進行状況を表示でき、onProgressUpdateに進行状況ダイアログまたは進行状況バーを配置できます。

于 2012-12-01T11:57:56.600 に答える