2014-06-11 53 views
1

我正在開發一個需要通過套接字傳輸一些數據的android應用程序。此時它連接到套接字,單擊接口按鈕時發送消息,但是當套接字類收到消息時,我想在接口上使用AlertDialog提醒用戶。我一直在搜索並找到有關處理程序的信息,但我無法使用它們。我怎麼解決這個問題? 謝謝Socket類和UI之間的通信

+0

'通過接口按鈕發送消息???? '套接字類通過AlertDialog'方法接收消息問題是什麼??? – greenapps

+0

對不起,我英文很差,我編輯並試圖讓它現在變得更好。謝謝 –

+0

如果你可以顯示AlertDialog,那麼究竟是什麼問題? – greenapps

回答

1
MainActivity.this.runOnUiThread(new Runnable() { 
    @Override 
    public void run() { 
     // Build an alert dialog 
     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this) 
       .setTitle("Title") 
       .setMessage("Message") 
       .setCancelable(false) 
       .setPositiveButton("Done", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog,int id) { 
         // Close the dialog 
         dialog.cancel(); 
        } 
        }); 

     // Create the alert dialog 
     AlertDialog alertDialog = alertDialogBuilder.create(); 

     // Show the alert dialog 
     alertDialog.show(); 
    } 
});