package zhang.progress;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
public class Prpgress extends Activity {
private ProgressBar p1;
private ProgressBar p2;
private Button myButton;
private int i=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
p1=(ProgressBar)findViewById(R.id.p1);
p2=(ProgressBar)findViewById(R.id.p2);
myButton=(Button)findViewById(R.id.button);
myButton.setOnClickListener(new ButtonListener());
}
class ButtonListener implements OnClickListener{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(i==0)
{
p1.setVisibility(View.VISIBLE);
p2.setVisibility(View.VISIBLE);
}
else if(i<p1.getMax()){
p1.setProgress(i);
p2.setSecondaryProgress(i+10);
p2.setProgress(i);
}
else{
p1.setVisibility(View.GONE);
p2.setVisibility(View.GONE);
}
i=i+10;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ProgressBar
android:id="@+id/p1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<ProgressBar
android:id="@+id/p2"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start"
/>
</LinearLayout>