xutils

官网地址:https://github.com/wyouflf/xUtils

#趣米杯#快速开发之xUtils(一)简介以及使用方法

http://www.apkbus.com/android-157640-1-1.html

#趣米杯#快速开发之xUtils(二)ViewUtils介绍

http://www.apkbus.com/forum.php?mod=viewthread&tid=157641&highlight=%23%E8%B6%A3%E7%B1%B3%E6%9D%AF%23%E5%BF%AB%E9%80%9F%E5%BC%80%E5%8F%91%E4%B9%8BxUtils 

#趣米杯#快速开发之xUtils(三)DbUtils介绍

http://www.apkbus.com/android-157644-1-1.html 

增加:

1、

for (int i = 0; i <5; i++) {
    User user=new User();
    user.setUserName("liyuhao"+i);
    user.setPassword("123456"+i);
    try {
     db.save(user);
    } catch (DbException e) {
     e.printStackTrace();
    }
   }

2、

List<User> users=new ArrayList<User>();
    for (int i = 0; i <5; i++) {
    User user=new User();
    user.setUserName("liyuhao"+i);
    user.setPassword("123456"+i);
    users.add(user);
   }


   try {
    db.saveAll(users);
   } catch (DbException e) {
    e.printStackTrace();
   }

3、

for (int i = 0; i <5; i++) {
    try {
     db.getDatabase().execSQL("insert into user(username,password) values(?,?)", new String[]{"liyuhao"+i,"123456"+i});  
    } catch (Exception e) {
     e.printStackTrace();
    }
   }

删除:

1、db.getDatabase().execSQL("delete from user where userName=? and password=?", bindArgs);

2、db.delete(User.class, WhereBuilder.b("userName", "=", "liyuhao1").and("password", "=", "1234561"));

3、db.deleteAll(User.class);//相当于delete from user;

修改:

1、db.getDatabase().execSQL("update user set userName=? where password=?", new String[]{"liyuhaoX","1234560"});

2、修改所有的密码为123

List<User> list = db.findAll(User.class);
   for (User user : list) {
    user.setPassword("123");
   }
   db.updateAll(list, "password");

3、User user=new User();
   user.setId(1);
   user.setUserName("liyuhao1");
   db.update(User.class, WhereBuilder.b("password", "=", "123456"), "password");

查询:

public List<Map<String,Object>> get()

{

      List<Map<String,Object>> result=new arrayList<Map<String,Object>>();

      Cuseror cursor=db.rawQuery(String sql);

      while(cursor.moveToNext())

     {

            Map<String,Objcet> map=new HashMap<String,Objcet>();

           map.put("username",cursor.getString(0));

           result.add(map);

       }

#趣米杯#快速开发之xUtils(四)HttpUtils介绍

http://www.apkbus.com/forum.php?mod=viewthread&tid=157645&highlight=%23%E8%B6%A3%E7%B1%B3%E6%9D%AF%23%E5%BF%AB%E9%80%9F%E5%BC%80%E5%8F%91%E4%B9%8BxUtils

HttpUtils http = new HttpUtils();
   RequestParams params = new RequestParams();
   params.addBodyParameter("username", username);
   params.addBodyParameter("password", password);
   http.send(HttpMethod.POST, Constent.LOGIN_URL, params, new RequestCallBack<String>() {
    @Override
    public void onStart() {
     pd.show();
    }

    @Override
    public void onLoading(long total, long current, boolean isUploading) {
     LogUtils.d("total=" + total + ",current=" + current + ",isUploading=" + isUploading);
    }

    @Override
    public void onSuccess(ResponseInfo<String> responseInfo) {
     Gson gson = new Gson();
     MessageInfo mi = gson.fromJson(responseInfo.result, MessageInfo.class);

 ArrayList<GongGao> gongGaos = gson.fromJson(responseInfo.result, new TypeToken<ArrayList<GongGao>>() {
    }.getType());

}

@Override
    public void onFailure(HttpException error, String msg) {
     pd.dismiss();
     Toast.makeText(LoginActivity.this, "联网失败。", Toast.LENGTH_SHORT).show();
     LogUtils.d("msg=" + msg);
    }

其中 onSuccess(),onFailure()是抽象方法,必须实现。

 

 

 

 

 

InputStream is = getResources().openRawResource(R.raw.a);
  try {
   String str = StreamTool.inputStream2String(is);
   String[] split = str.split("\\|");
   if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
   File sdcardDir = Environment.getExternalStorageDirectory();
   String path=sdcardDir.getPath()+"/carImages";
   final File path1 = new File(path);
    if (!path1.exists()) {
              //若不存在,创建目录,可以在应用启动的时候创建
              path1.mkdirs();
            }
   }
   httpUtils = new HttpUtils(5 * 1000);
   for (int i = 0; i < split.length; i++) {
    System.out.println("what:"+split[i]);
    //下载图片到指定的文件夹中
    httpUtils.send(HttpMethod.GET, split[i], new RequestCallBack<Bitmap>() {

     @Override
     public void onFailure(HttpException arg0, String arg1) {
      
     }

     @Override
     public void onSuccess(ResponseInfo<Bitmap> arg0) {
      FileOutputStream out;
      try {
       out = new FileOutputStream(Environment.getExternalStorageDirectory().getPath()+"/carImages");
       arg0.result.compress(Bitmap.CompressFormat.PNG, 90, out);
       out.flush();
       out.close();
      } catch (Exception e) {
       e.printStackTrace();
      }
      
     }
    });
   }
  } catch (IOException e1) {
   e1.printStackTrace();
  }

你可能感兴趣的:(xutils)