我想从数据库中获取图像并在ImageView中设置? 我尝试了很多,但没有得到输出
这里我尝试这种方式来获取图片: -
private class fetchprofile extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setTitle("Please Wait");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... args) {
try {
arraylist = new ArrayList<HashMap<String, String>>();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("at_username", uid));
JSONObject json = jParser.makeHttpRequest(url_visitor, "GET", params);
ownerObj = json.getJSONArray("profile");
for (int i = 0; i < ownerObj.length(); i++) {
// uid= json.getJSONArray("v_parties").getJSONObject(0).getString("count");
jsonobject = ownerObj.getJSONObject(i);
img="http://10.0.2.2/profile/image/";
image.add(img + jsonobject.getString("pp_image"));
user_name=jsonobject.getString("pp_username");
departmenta=jsonobject.getString("pp_department");
email_id=jsonobject.getString("pp_email");
phone=jsonobject.getString("pp_phone");
DEsgination=jsonobject.getString("pp_designation");
Addresss=jsonobject.getString("pp_address");
}
} catch (Exception e) {
}
return null;
}
@Override
protected void onPostExecute(Void args ) {
image123.setImageBitmap(Bitmap.bitmap);
username.setText(user_name.toString());
department.setText(departmenta.toString());
email.setText(email_id.toString());
mobile.setText(phone.toString());
designation.setText(Addresss.toString());
address.setText(Addresss.toString());
}
}
我试过这种方式但没有在ImageView中获取图像。
答案 0 :(得分:1)
根据网址,您可以使用an image-loading library将图片加载到ImageView
,例如Picasso。
在你的情况下,你有N张图片,据我所知,你只有一张ImageView
。您可以自行决定将哪N个图像加载到ImageView
中。