2

I have written a program to get json data from a url which has one image which is in base64 and other textview data , i am able to display the data inside my textviews, and i am also able to convert it to bitmap but i dont know how to use it in my code, i am using imageloader library to display my image. I need some help

 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);

The above code is used to get all the json data from the url , and i have commented out the code where i am converting base64 to bitmap , but i dont know how to add it into my arraylist which only accepts string.

My 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;
}

}

Method from imageloader class

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);
    }
}

I also tried to add an arraylist which accepts string and bitmap but i am getting an error on the above method as the method only accepts string and imageview but not bitmap and imageview

Need some help to display and convert the base64 into my imageview.

Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
narahari_arjun
  • 623
  • 1
  • 13
  • 30
  • 1
    Look this : http://stackoverflow.com/questions/4837110/how-to-convert-a-base64-string-into-a-bitmap-image-to-show-it-in-a-imageview – SANAT Aug 05 '15 at 06:05
  • http://stackoverflow.com/questions/4837110/how-to-convert-a-base64-string-into-a-bitmap-image-to-show-it-in-a-imageview?answertab=active#tab-top – IntelliJ Amiya Aug 05 '15 at 06:06

0 Answers0