<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      【Android學習筆記】HTTP POST & WorkThread

      HTTP Post的簡單用法,和多線程的簡單用法:

      WebService:

      [WebMethod]
      public bool Login(string account,string password)
      {
      if ("larrylee" == account & "123456" == password)
      return true;
      else
      return false;
      }

      Login Activity:

      package com.mtk.lc.LoginDemo;

      import java.util.ArrayList;
      import java.util.List;

      import org.apache.http.NameValuePair;
      import org.apache.http.message.BasicNameValuePair;

      import android.app.Activity;
      import android.os.Bundle;
      import android.os.Handler;
      import android.os.Message;
      import android.view.View;
      import android.widget.Button;
      import android.widget.EditText;
      import android.widget.Toast;

      public class LoginDemo extends Activity {
      EditText editTextAccount;
      EditText editTextPsw;
      Button buttonLogin;
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      editTextAccount
      =(EditText) findViewById(R.id.editTextAccount);
      editTextPsw
      =(EditText) findViewById(R.id.editTextPsw);
      buttonLogin
      =(Button) findViewById(R.id.buttonLogin);
      buttonLogin.setOnClickListener(
      new View.OnClickListener() {

      @Override
      public void onClick(View v) {
      List
      <NameValuePair> params=new ArrayList<NameValuePair>();
      params.add(
      new BasicNameValuePair("account", editTextAccount.getText().toString()));//傳遞參數
      params.add(new BasicNameValuePair("password", editTextPsw.getText().toString()));//傳遞參數
      HTTPThread httpThread=new HTTPThread(loginHandler);
      //在工作線程中執行耗時任務,防止UI線程阻塞
      httpThread.doStart("http://10.0.2.2:2161/WebSite1/Service.asmx/Login", params, LoginDemo.this);
      //10.0.2.2為電腦對于模擬器而言的IP地址。
      }
      });
      }
      private Handler loginHandler=new Handler(){
      public void handleMessage(Message message) {
      switch (message.what) {
      case 1://程序執行正常
      Boolean res=message.getData().getBoolean("login");
      if(res){//成功登陸
      Toast.makeText(LoginDemo.this, "Successd!", Toast.LENGTH_LONG).show();
      }
      else{//登陸失敗
      Toast.makeText(LoginDemo.this, "Fail!", Toast.LENGTH_LONG).show();
      }
      break;

      default://程序異常...(網絡連接出錯)
      Toast.makeText(LoginDemo.this, "Error!", Toast.LENGTH_LONG).show();
      break;
      }
      }
      };

      }

      Http Thread

      package com.mtk.lc.LoginDemo;

      import java.io.IOException;
      import java.util.List;

      import org.apache.http.NameValuePair;
      import org.apache.http.ParseException;
      import org.apache.http.client.ClientProtocolException;
      import org.apache.http.client.HttpClient;
      import org.apache.http.client.entity.UrlEncodedFormEntity;
      import org.apache.http.client.methods.HttpPost;
      import org.apache.http.impl.client.DefaultHttpClient;
      import org.apache.http.protocol.HTTP;
      import org.apache.http.util.EntityUtils;

      import android.app.ProgressDialog;
      import android.content.Context;
      import android.content.DialogInterface;
      import android.os.Bundle;
      import android.os.Handler;
      import android.os.Message;

      public class HTTPThread extends Thread {
      ProgressDialog pdDialog
      = null;
      String urlString
      = null;
      List
      <NameValuePair> params = null;
      Handler handler
      = null;

      public HTTPThread(Handler handler) {
      this.handler = handler;
      }

      public void doStart(String urlString, List<NameValuePair> params,
      Context context) {
      //進行一些初始化工作然后調用start()讓線程運行
      this.urlString = urlString;
      this.params = params;
      pdDialog
      = new ProgressDialog(context);
      pdDialog.setTitle(
      "Login...");
      pdDialog.setMessage(
      "Connecting to Server...");
      pdDialog.setIndeterminate(
      true);
      pdDialog.setButton(
      "Cancel", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
      pdDialog.cancel();
      }
      });
      pdDialog.show();
      this.start();
      }

      @Override
      public void run() {
      Message msg
      = new Message();
      Bundle data
      = new Bundle();
      try {
      boolean result = webServiceLogin();//執行網絡服務請求,耗時操作。。。
      msg.what=1;
      data.putBoolean(
      "login", result);
      data.putString(
      "info", "normal");
      msg.setData(data);
      }
      catch (ParseException e) {
      msg.what
      =2;
      data.putString(
      "info", "Error");
      msg.setData(data);
      e.printStackTrace();
      }
      catch (ClientProtocolException e) {
      msg.what
      =2;
      data.putString(
      "info", "Error");
      msg.setData(data);
      e.printStackTrace();
      }
      catch (IOException e) {
      msg.what
      =2;
      data.putString(
      "info", "Error");
      msg.setData(data);
      e.printStackTrace();
      }
      finally {
      pdDialog.dismiss();
      handler.sendMessage(msg);
      }
      }

      private boolean webServiceLogin() throws ParseException,
      ClientProtocolException, IOException {
      HttpClient httpClient
      = new DefaultHttpClient();//HTTP客戶端,使用默認客戶端
      HttpPost httpPost = new HttpPost(urlString);//建立HttpPost對象
      httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));//設置參數
      String res = EntityUtils.toString(httpClient.execute(httpPost)
      .getEntity());
      //執行并返回結果:

      // <?xml version="1.0" encoding="utf-8" ?>
      // <boolean xmlns="http://tempuri.org/">true</boolean>

      if (res.contains("true")) {//偷個懶不對XML進行解析了,返回中有true就是登陸成功了。
      return true;
      }
      return false;
      }
      }

      Layout:

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation
      ="vertical" android:layout_width="fill_parent"
      android:layout_height
      ="fill_parent">
      <TextView android:id="@+id/textView1" android:layout_width="wrap_content"
      android:layout_height
      ="wrap_content" android:text="Account:"
      android:textSize
      ="10pt"></TextView>
      <EditText android:layout_height="wrap_content"
      android:layout_width
      ="match_parent" android:id="@+id/editTextAccount"></EditText>
      <TextView android:id="@+id/textView2" android:layout_width="wrap_content"
      android:layout_height
      ="wrap_content" android:textSize="10pt"
      android:text
      ="Pass Word:"></TextView>
      <EditText android:layout_height="wrap_content"
      android:layout_width
      ="match_parent" android:id="@+id/editTextPsw"
      android:password
      ="true"></EditText>
      <Button android:layout_width="wrap_content"
      android:layout_height
      ="wrap_content" android:id="@+id/buttonLogin"
      android:text
      ="Login"></Button>
      </LinearLayout>
      posted @ 2011-04-18 13:41  Cat_Lee  閱讀(1533)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 日本一区二区三区视频一| 久热伊人精品国产中文| 日韩有码中文字幕av| 亚洲自拍偷拍一区二区三区 | 怡春院久久国语视频免费| 欧美和黑人xxxx猛交视频| 亚洲欧美人成人让影院| 国产亚洲综合欧美视频| 五十路丰满中年熟女中出| 中文字幕亚洲人妻一区| 亚洲高清成人av在线| 国产啪视频免费观看视频| 97色伦97色伦国产| 亚洲一区二区三级av| 欧美亚洲综合成人A∨在线| 重口SM一区二区三区视频| 无码国产偷倩在线播放老年人| 中文字幕日韩有码国产| 亚洲综合网国产精品一区| 成人亚洲一级午夜激情网| 国产一区二区三区导航| 性无码一区二区三区在线观看| 图片区 小说区 区 亚洲五月 | 九九久久精品国产| 日韩福利片午夜免费观着| 老妇xxxxx性开放| 裸身美女无遮挡永久免费视频| 国产漂亮白嫩美女在线观看| 国产亚洲一在无在线观看| 377p欧洲日本亚洲大胆| 亚洲天天堂天堂激情性色| 亚洲av永久无码精品水牛影视| 久久久国产乱子伦精品作者| 激情文学一区二区国产区| 亚洲精品麻豆一二三区| 成人网站免费看黄a站视频| 少妇被粗大的猛烈进出 | 无码人妻一区二区三区在线视频 | 人妻少妇精品视频无码综合| 在线看无码的免费网站| 扬州市|