0

I want to design and implement a progress bar. But i have some problems.

My progress bar layout like this

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

My problem is about android:max. Is there a way to change it with user's choice. For example user maybe wants to set 1500 for max value. I want to do it with plain text. (User must enter his/her value to plain text).

How can i implement it on java side?

hakki
  • 6,181
  • 6
  • 62
  • 106

1 Answers1

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.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • Solution is ok, thank a lot. But if i have 2 activites, assume EditText in ActivityA and ProgressBar in ActivityB. What it the approach? – hakki Feb 24 '13 at 21:04
  • 1
    @hakiko Take the input in ActivitA, and pass it as an Intent Extra to ActivityB. Then retrieve it and set it using setMax(). – Raghav Sood Feb 24 '13 at 21:05