关于调用库需要澄清

时间:2013-07-25 15:37:29

标签: android

请你帮我解决android库的使用问题。

  1. 我点击了一个需要调用库的go按钮。
  2. 图书馆依次启动登录屏幕
  3. 登录屏幕接受用户ID,密码点击URL并返回响应(成功/失败)
  4. http帖子的代码(需要用作库)是:

    username =(EditText)findViewById(R.id.editTextusername);          password =(EditText)findViewById(R.id.editTextpassword);

         submit = (Button)findViewById(R.id.submit);
    
    
         submit.setOnClickListener(new View.OnClickListener() {
    
    @Override
    public void onClick(View v) {
    
        // TODO Auto-generated method stub
        if(username.getText().length()>0 && password.getText().length()>0)
        {
            URLconnector ss = new URLconnector();
            ss.execute("http//ipchicken.com");
        }
    }
    

    });

    }
    
    private class URLconnector extends AsyncTask<String, Void, String> {
    
        @Override
        protected String doInBackground(String... urls) {
            String response = "";
            for (String url : urls) {
    
                DefaultHttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(url);
                try {
    
    
    
                    List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    
    
    
                    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
                            postParameters);
    
                    httppost.setEntity(formEntity);
    
                    HttpResponse response1 = httpclient.execute(httppost);
    
                    BufferedReader in = new BufferedReader(
                            new InputStreamReader(response1.getEntity()
                                    .getContent()));
                    StringBuffer sb = new StringBuffer("");
    
                    String line = "";
                    String NL = System.getProperty("line.separator");
                    while ((line = in.readLine()) != null) {
                        sb.append(line + NL);
                    }
                    in.close();
    
                    String result = sb.toString();
                    response = result;
                    System.err.println("My Response :: " + result);
    
                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return response;
    
        }
    
        protected void onPostExecute(String result) {
            if(result != null)
            {
            Intent tokenIntent = new Intent(mContext, tokenActivity.class);
             Bundle bundle = new Bundle();
             bundle.putString("responsedata",result);
    
            tokenIntent.putExtras(bundle);
            startActivity(tokenIntent);
            }
    

0 个答案:

没有答案