0

プログレスバーを設計して実装したい。しかし、私にはいくつかの問題があります。

このような私の進行状況バーのレイアウト

<ProgressBar
    android:id="@+id/progress1"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:max="100"
    android:maxHeight="5sp"
    android:progress="45" />

MyActivity.java

ProgressBar pb1 = (ProgressBar) findViewById(R.id.progress1);

私の問題は約android:maxです。ユーザーの選択でそれを変更する方法はありますか。たとえば、ユーザーは最大値を 1500 に設定したいと思うかもしれません。プレーンテキストでやりたい。(ユーザーは自分の値をプレーン テキストに入力する必要があります)。

Java側でどのように実装できますか?

4

1 に答える 1

2
ProgressBar pb1 = (ProgressBar) findViewById(R.id.progress1);
pb1.setMax(1500);

You can take the value from the user in an EditText, and the convert it to an int from a String using Integer.parseInt(). Then simply pass that int to the setMax() method to change the maximum value.

于 2013-02-24T21:01:39.253 に答える