Activity to Simulate

I mean to create a simple activity to simulate the progressbar we have created. please take a look at full code below:

1. Declare variables needed for simulation:

private ARProgressBar ap;
private static final int PROGRESS = 0xDEADBEEF;
protected int mProgress;
protected boolean mCancelled;

2. Fill code at onCreate() on Activity class:

public void onCreate(Bundle icicle)
{

super.onCreate(icicle);
setContentView(R.layout.main);
ap = (ARProgressBar) this.findViewById(R.id.cProgres);
mCancelled = false;
Button b = (Button) this.findViewById(R.id.btnSimulate); 
b.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
mCancelled = false;
mHandler.sendMessage(
mHandler.obtainMessage(PROGRESS));
});
Button bStop= (Button) this.findViewById(R.id.btnStop);
bStop.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
mCancelled = true;
});


}


3. Create mHandler variabel as a Handler Message

protected Handler mHandler = new Handler() {

@Override
public void handleMessage(Message msg) {
if ((msg.what == PROGRESS) && (!mCancelled)) {
mProgress += 50;
ap.setPosition(mProgress/100);
if (mProgress > 10000) {
mProgress = 0; 
}
sendMessageDelayed(obtainMessage(PROGRESS), 50);
}

};

4. Compile and push to the emulator and run you will have your progress bar running by clicking Simulate Button, and stop it by clicking Stop button.



Was This Information Help ?

Comments