0

我是安卓新手。。

我在应用程序中遇到问题..

我一直在尝试几种显示 JSON 图像的方法,但我的解决方案从未成功。

在我的数据库中,图像存储在一个文件夹中。所以在我的 JSON 对象中,我得到了图像的 scr 路径。现在我想在模拟器中显示图像。我的 JSON 对象中的路径如下:“imgsrc=question/images/u2_1_l2_q66”。我已将路径存储在 imgarr 数组中。

如何显示来自该路径的图像?我想将图像文件夹添加到drawables。请帮助我。非常感谢。

代码

       protected String doInBackground(String... args) {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("tid", tid));
    json = jsonParser.makeHttpRequest(url_get_quesurl, "GET", params);
    Log.d("All Groups: ", json.toString());
    try {
    int success = json.getInt(TAG_SUCCESS);
    if (success == 1) {
        System.out.println("Success");
        groups = json.getJSONArray(TAG_GROUP);
        System.out.println("Result Success+++"+groups);
         for (int i = 0; i < groups.length();i++) {
        JSONObject c = groups.getJSONObject(i);
        String question = c.getString(TAG_QUES);
        System.out.println("Checking ::"+question);
        ques1.add(question);
        String img = c.getString(TAG_IMAGE);
        System.out.println("Checking ::"+img);
        imgarr.add(img);
         }
    } else {
        showAlert();
    }
} catch (JSONException e) {
    System.out.println("Error "+e.toString());
}
return null;
}
 protected void onPostExecute(String file_url) {
    pDialog.dismiss();
    ques1=new ArrayList<String>(new ArrayList<String>(ques1));
    imgarr=new ArrayList<String>(new ArrayList<String>(imgarr));
    TextView txtque = (TextView) findViewById(R.id.que_txt); 
    txtque.setText("Q" + num + ")" + ques1.get(j) + imgarr.get(g));
       } 
4

2 回答 2

0

在我的数据库中,图像存储在一个文件夹中

获得文件的完整路径后,只需将包装好的文件对象传递给 BitmapFactory,并在 ImageView 中显示 Bitmap

private Bitmap decodeFile(File f)
{
 try 
 {
//you might want to downscale it....
  return BitmapFactory.decodeStream(new FileInputStream(f),null,o);
 }
 catch (FileNotFoundException e) 
 {
  //throw exception
 }
 return null;
}
于 2013-02-19T10:39:11.937 回答
0

您需要下载图像数据,解码然后显示。我建议您使用 Universal Image Loader等库。

于 2013-02-19T11:06:23.353 回答