Created
July 6, 2014 11:23
-
-
Save gmsetiawan/935909fc7e0bac75ef9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FormWidgetActivity extends Activity{ | |
private Handler progressBarHandler = new Handler(); | |
ProgressBar mProgressBar, mProgressBarHorizontal; | |
int iProgressBarStatus = 0; | |
TextView tvStatusProgressBar; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
// TODO Auto-generated method stub | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_formwidget); | |
/...../ | |
tvStatusProgressBar = (TextView) findViewById(R.id.textView5); | |
mProgressBarHorizontal = (ProgressBar) findViewById(R.id.progressBar1); | |
mProgressBar = (ProgressBar) findViewById(R.id.progressBar2); | |
Button btnProgress = (Button) findViewById(R.id.button2); | |
btnProgress.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
// TODO Auto-generated method stub | |
new Thread(new Runnable() { | |
@Override | |
public void run() { | |
// TODO Auto-generated method stub | |
while (iProgressBarStatus < 100) { | |
try { | |
iProgressBarStatus += 10; | |
progressBarHandler.post(new Runnable() { | |
@Override | |
public void run() { | |
// TODO Auto-generated method stub | |
mProgressBar.setProgress(iProgressBarStatus); | |
mProgressBar.setIndeterminate(true); | |
mProgressBarHorizontal.setProgress(iProgressBarStatus); | |
tvStatusProgressBar.setText(iProgressBarStatus+"/"+mProgressBarHorizontal.getMax()); | |
} | |
}); try { | |
Thread.sleep(200); | |
} catch (Exception e) { | |
// TODO: handle exception | |
} | |
} catch (Exception e) { | |
// TODO: handle exception | |
e.printStackTrace(); | |
} | |
} | |
} | |
}).start(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment