Android Coding
Thread UI 처리에 대한 샘플
오마로
2017. 11. 29. 14:35
반응형
Thread UI 처리에 대한 샘플
public class YourClass extends Activity { private Button myButton; //create an handler private final Handler myHandler = new Handler(); final Runnable updateRunnable = new Runnable() { public void run() { //call the activity method that updates the UI updateUI(); } }; private void updateUI() { // ... update the UI } private void doSomeHardWork() { //.... hard work //update the UI using the handler and the runnable myHandler.post(updateRunnable); } private OnClickListener buttonListener = new OnClickListener() { public void onClick(View v) { new Thread(new Runnable() { doSomeHardWork(); }).start(); } };}http://crodrigues.com/updating-the-ui-from-a-background-thread-on-android/
반응형