用json和图像处理asynctask

时间:2013-04-21 22:58:26

标签: java android

你好,我现在没有运气,因为在我把一个网址拉出来后如何处理一个图像因为async只允许一次返回有人有什么建议吗?

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String json) {
        // dismiss the dialog after getting song information

        try {
               JSONObject jsonObject = new JSONObject(json);
               JSONArray jsonArray = jsonObject.getJSONArray("users");
               JSONObject arrayElement_0 = jsonArray.getJSONObject(0);
               uname = arrayElement_0.getString(TAG_USERNAME);
               ptitle = arrayElement_0.getString(TAG_PROFILETITLE);
               age = arrayElement_0.getString(TAG_AGE);
               gender = arrayElement_0.getString(TAG_GENDER);
               status = arrayElement_0.getString(TAG_STATUS);
               small = arrayElement_0.getString(TAG_SMALL);

        BitmapFactory.decodeStream((InputStream)new URL(small).getContent());

3 个答案:

答案 0 :(得分:0)

如果你需要返回多个东西,只需返回一个数组。

答案 1 :(得分:0)

创建一个可以同时包含Bitmap和其他数据的类?虽然将Bitmap保留在一个类中是一个坏主意(它们使用大量内存)。一般来说,最好单独处理位图。

答案 2 :(得分:0)

对于其他人如何做到这一点,这是最好的例子希望这有助于:) http://codehenge.net/blog/2011/06/android-development-tutorial-asynchronous-lazy-loading-and-caching-of-listview-images/