Android 台灣中文網

標題: 為甚麼我的toast 無法顯示? [打印本頁]

作者: kira800917    時間: 2013-10-11 13:32
標題: 為甚麼我的toast 無法顯示?
本帖最後由 kira800917 於 2013-10-11 13:36 編輯

public void FN() {
                Thread networkThread = new Thread() {
                        @Override
                        public void run() {

                                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

                                request.addProperty("acc", et_id.getText().toString());
                                request.addProperty("pwd", et_pwd.getText().toString());

                                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                                                SoapEnvelope.VER11);
                                envelope.dotNet = true;
                                envelope.setOutputSoapObject(request);
                                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

                                try {
                                        sleep(500);
                                        /** 開始呼叫 Web Service */
                                        androidHttpTransport.call(SOAP_ACTION, envelope);
                                        SoapPrimitive response = (SoapPrimitive) envelope
                                                        .getResponse();

                                        Log.i("myApp", response.toString());
                                        flag = response.toString();
                                        int_flag = flag.compareTo("t");

                                        if (r_data == null) {
                                                sleep(500);
                                                if (int_flag == 0) {

                                                        Log.i("r_data 還沒抓到值", "!!!!!!!!!!!!!!!!");

                                                        Intent intent = new Intent();
                                                        Bundle bundle = new Bundle();
                                                        bundle.putString("s_id", et_id.getText().toString());
                                                        bundle.putString("data", r_data);
                                                        intent.setClass(getActivity(), Fragment2_1.class);

                                                        intent.putExtras(bundle);
                                                        startActivity(intent);
                                                        Log.i("myApp", "ok");

                                                }

                                        } else {

                                       

                                                        Toast.makeText(getActivity(), "密碼錯誤!",
                                                                        Toast.LENGTH_SHORT).show();

                                               

                                        }

                                } catch (Exception e) {
                                        e.printStackTrace();

                                }

                        }

                };
                networkThread.start();

        }
作者: ploglin    時間: 2013-10-11 17:34
你先在Toast的地方下Log,看邏輯是否正確。
如果正確的話,看看有沒有錯誤訊息讓大家解析一下。
作者: whl    時間: 2013-10-11 18:46
Toast 是在 ui 下執行當然不會顯示。
作者: lkk47    時間: 2013-10-11 22:48
try it  依樣放在 if..else
  1. activity.runOnUiThread(new Runnable() {
  2.                        
  3.                         @Override
  4.                         public void run() {
  5.                                 // TODO Auto-generated method stub
  6.                                 Toast.makeText(getActivity(), "密碼錯誤!",
  7.                                                                         Toast.LENGTH_SHORT).show();


  8.                         }
  9.                 });
複製代碼

作者: kira800917    時間: 2013-10-12 11:21
謝謝大家。我以解決摟~
我自己是用Handler來解決的!~~






歡迎光臨 Android 台灣中文網 (https://apk.tw/) Powered by Discuz! X3.1