LoginSignup
48
48

More than 5 years have passed since last update.

Android Query超いいよ

Posted at

Android Query(AQuery)を使ってみました。AQuery:jQuery for Androidの紹介にあるように、WEBアクセスが必要な時にいちいちLoaderとか使わないで、しかも簡潔に記述できるので使って損はないと思います。

AQuery aQuery = new AQUery(this);

// 非同期でURLにアクセスして、結果をJSONで受け取る
final Progress progress = new ProgressDialog(this);
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progress.setMessage("Now Loading...");
progress.show();

aQuery .ajax("http://hogehoge.com", JSONObject.class, new AjaxCallback<JSONObject>() {
    /* (非 Javadoc)
     * @see com.androidquery.callback.AbstractAjaxCallback#callback(java.lang.String, java.lang.Object, com.androidquery.callback.AjaxStatus)
     */
    @Override
    public void callback(String url, JSONObject object, AjaxStatus status) {
        super.callback(url, object, status);

        try {
            JSONObject jsonDataObject = object.getJSONObject("data");
            JSONArray jsonDataArray = jsonDataObject.getJSONArray("array");
            JSONObject jsonObj = (JSONObject)jsonDataArray.get(0);

        } catch (Exception e) {
            e.getMessage();
        } finally {
            progress.dismiss();
        }
    }
});

48
48
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
48
48