20.11.2016 Views

ANDROID APP

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

94 บทที่ 4 ส่วนการติดต่อกับผู้ใช้งาน (User Interface)<br />

}<br />

public void onClick(View view) {<br />

do_work();<br />

}<br />

});<br />

//example of a computationally intensive action with UI updates<br />

private void do_work() {<br />

Thread thread = new Thread(new Runnable() {<br />

public void run() {<br />

text_string=R.string.start;<br />

background_color = Color.DKGRAY;<br />

mHandler.post(mUpdateResults);<br />

computation(1);<br />

text_string=R.string.first;<br />

background_color = Color.BLUE;<br />

mHandler.post(mUpdateResults);<br />

}<br />

computation(2);<br />

text_string=R.string.second;<br />

background_color = Color.GREEN;<br />

mHandler.post(mUpdateResults);<br />

}<br />

});<br />

thread.start();<br />

}<br />

final static int SIZE=1000; //large enough to take some time<br />

double tmp;<br />

private void computation(int val) {<br />

for(int ii=0; ii

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!