Last active
February 1, 2016 13:53
-
-
Save jbruchanov/7f5704e3f2b690b1200e 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 MyActivity extends Activity implements PBarChange { | |
private ProgressBar mPbar; | |
private MyThread mMyThread; | |
public void onCreate(...){ | |
super.onCreate(...); | |
setContentView(R.id.content); | |
mPbar = (ProgressBar)findViewById(R.id.pbar); | |
mMyThread = new MyThread(this); | |
mMyThread.start(); | |
} | |
public void onDestroy(){ | |
mMyThread.stop(); | |
} | |
public void onProgressChanged(int progress){ | |
mPbar.setProgress(progress); | |
} | |
} | |
public class MyThread extends Thread { | |
public interface PBarChange { | |
void onProgressChanged(int progress); | |
} | |
private Handler mHandler; | |
private int mProgress; | |
private boolean mIsRunning = true; | |
public class MyThread(PBarChange listener){ | |
mListener = listener; | |
mHandler = new Handler(Looper.getMainLooper()); | |
} | |
public void run() { | |
while(mIsRunning) { | |
mProgress = 10...; | |
mHandler.post(mUpdateAction); | |
} | |
} | |
public void stop(){ | |
mIsRunning = false; | |
} | |
private Runnable mUpdateAction = new Runnable(){ | |
public void run(){ | |
mListener.onProgressChanged(mProgress); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment