AndroidStudio 最常用代码

X. 快捷键
Ctrl +Y  删除行
Ctrl+/   选中某一行,同时按下Ctrl+/快捷键可以注释这一行




X.  http接口(POST)

    //XXX数据
    public void getXXXXXXXX(String device_id){

        try {
            // { "deviceid", "XXXXXX" }
            JSONObject req_json = new JSONObject();
            req_json.put("deviceid", device_id); //设备id

            String jsonString=req_json.toString();

            // 发送和接收数据处理
            HttpUtil.doPostJsonAsync("http://XXXXXXXXX",
                jsonString, new HttpUtil.CallBack() {

                    @Override
                    public void onRequestStringComplete(String result) {
                        JSONObject ret_json = null;
                        try {
/*
{
  "id": 1,
  "sleeptotal": 16,
}
*/
                            ret_json = new JSONObject(result);

                            if (ret_json == null) {
                                Toast.makeText(smartBraceletActivity.this, CurrentLineInfo.getFileName() + CurrentLineInfo.getStrLineNumber()
                                        + "系统错误,请稍候再试!", Toast.LENGTH_SHORT).show();
                                return;
                            }

                            tv_sleeptotal.setText( ret_json.getString("sleeptotal") );

                        } catch (JSONException e) {
                            e.printStackTrace();
                            return;
                        }
                    }

                    @Override
                    public void onRequestBitmapComplete(Bitmap result) {
                        return;
                    }
                });

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

    }

 

你可能感兴趣的:(AndroidStudio)