一起學android之利用回呼函數onCreateDialog實現載入對話方塊(23)

來源:互聯網
上載者:User

標籤:dialog   android   對話方塊   載入對話方塊   java   




有時候我們需要去做一個Activity啟動時的資料載入對話方塊,關於對話方塊的各種實現可以通過一起學android之對話方塊


Dialog的建立(7)來完成,在這裡另外介紹一個,利用onCreateDialog回調方法來實現,當然這個方法標記已經過


時了,但我們還是可以使用這個方法來實現我們想要的功能。具體請參看代碼:

public class MainActivity extends Activity {@SuppressWarnings("deprecation")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);new Thread(runable).start();showDialog(0);}@Overrideprotected Dialog onCreateDialog(int id) {ProgressDialog dialog=new ProgressDialog(this);if(id==0){dialog.setMessage("這是一個載入對話方塊...");}return dialog;}private Handler myHandler = new Handler() {@Overridepublic void handleMessage(Message msg) {dismissDialog(0);}};private final Runnable runable = new Runnable() {public void run() {try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}//類比載入資料2秒myHandler.obtainMessage().sendToTarget();}};}




轉載請註明出處:http://blog.csdn.net/hai_qing_xu_kong/article/details/44246735 情緒控_

一起學android之利用回呼函數onCreateDialog實現載入對話方塊(23)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.