我已经编写了一个程序来从一个url获取json数据,其中有一个图像位于base64和其他textview数据中,我能够在我的textview中显示数据,我也能够将它转换为位图但是我不知道如何在我的代码中使用它,我使用imageloader库来显示我的图像。 我需要一些帮助
url = url.toString().concat(veh_code);
httpCalls = new HTTPCalls();
JSONObject jsonObj = httpCalls.jo(url, imeiNumber, verificationCode,
appname);
try {
driverDetails = httpCalls.getJSONfromURL(url, imeiNumber,
clientCode, verificationCode);
for (int i = 0; i < driverDetails.length(); i++) {
JSONObject c = driverDetails.getJSONObject(i);
reg_no = c.getString(TAG_REGISTRATION_NO);
driver_name = c.getString(TAG_DRIVER_NAME);
driver_code = c.getString(TAG_DRIVER_CODE);
driver_photo = c.getString(TAG_DRIVER_PHOTO);
phone_no = c.getString(TAG_PHONE_NO);
// try{
// byte[] decodedString = Base64.decode(driver_photo,
// Base64.DEFAULT);
// Bitmap decodedByte =
// BitmapFactory.decodeByteArray(decodedString, 0,
// decodedString.length);
HashMap<String, String> driver_details = new
HashMap<String, String>();
driver_details.put(TAG_REGISTRATION_NO, reg_no);
driver_details.put(TAG_DRIVER_NAME, driver_name);
driver_details.put(TAG_DRIVER_CODE, driver_code);
driver_details.put(TAG_DRIVER_PHOTO, driver_photo);
driver_details.put(TAG_PHONE_NO, phone_no);
resultsList.add(driver_details);
//}
// catch(Exception e){
// e.printStackTrace();
// }
}
} catch (Exception e) {
e.printStackTrace();
}
ListViewAdapter adapter = new ListViewAdapter(getApplicationContext(),
resultsList);
lv.setAdapter(adapter);
上面的代码用于从url获取所有json数据,我已经注释掉了我将base64转换为位图的代码,但我不知道如何将它添加到我的arraylist中,它只接受字符串。< / p>
我的ListViewAdapter.java
public class ListViewAdapter extends BaseAdapter {
Context context;
LayoutInflater inflater;
ArrayList<HashMap<String, String>> data = new
ArrayList<HashMap<String,String>>();
ImageLoader imageLoader;
HashMap<String, String> resultp = new HashMap<String, String>();
int position;
TextView driverName, driverCode,reg_no,phone_no;
ImageView driverPhoto;
public ListViewAdapter(Context context, ArrayList<HashMap<String, String>>
arraylist) {
this.context = context;
data = arraylist;
imageLoader = new ImageLoader(context);
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.driver_details_row, parent,
false);
resultp = data.get(position);
driverName = (TextView) itemView.findViewById(R.id.DriverName);
driverCode = (TextView) itemView.findViewById(R.id.DriverCode);
reg_no = (TextView) itemView.findViewById(R.id.regNo);
phone_no = (TextView) itemView.findViewById(R.id.PhoneNo);
driverPhoto = (ImageView) itemView.findViewById(R.id.driverImage);
driverName.setText(resultp.get(DriverDetails.TAG_DRIVER_NAME));
driverCode.setText(resultp.get(DriverDetails.TAG_DRIVER_CODE));
reg_no.setText(resultp.get(DriverDetails.TAG_REGISTRATION_NO));
phone_no.setText(resultp.get(DriverDetails.TAG_PHONE_NO));
imageLoader.DisplayImage(resultp.get(DriverDetails.TAG_DRIVER_PHOTO),
driverPhoto);
return itemView;
}
}
来自imageloader类的方法
public void DisplayImage(String url, ImageView imageView) {
imageViews.put(imageView, url);
Bitmap bitmap = memoryCache.get(url);
if (bitmap != null)
imageView.setImageBitmap(bitmap);
else {
queuePhoto(url, imageView);
imageView.setImageResource(stub_id);
}
}
我还尝试添加一个接受字符串和位图的arraylist,但我在上面的方法上遇到错误,因为该方法只接受字符串和imageview但不接受位图和imageview
需要一些帮助才能显示base64并将其转换为我的imageview。