1

I have the EditText and Button, where I can put number in EditText of how many ImageView I want to display on my app. Let say, I write 3 then it will display 3 ImageViews on Layout and it works just fine.

I successfully take pictures and display it on those ImageViews.

container.removeAllViews();
                for (int i = 1; i <= no; i++) {
                    final View addView = layoutInflater.inflate(R.layout.shelter_row, null);
                    txtV1 = (TextView) addView.findViewById(R.id.txtV1);
                    txtV1.setText(String.valueOf(i));
                    addView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            imgLantai = (ImageView)view.findViewById(R.id.imgLantai);
                            Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                            startActivityForResult(intent,CAMERA_10);
                        }
                    });
                    container.addView(addView);
                }

I try to get the bitmap and display it on ImageView. It works

if(requestCode == CAMERA_10){
        if(resultCode == RESULT_OK){
            Bitmap bitmap = (Bitmap) data.getExtras().get("data");
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, output);
            byte[] byte_arr = output.toByteArray();
            mbitmap10 = Base64.encodeToString(byte_arr, Base64.DEFAULT);
            imgLantai.setImageBitmap(bitmap);
        }else if(resultCode == RESULT_CANCELED){
        }
    }

By using submit button I try to insert the bitmap to database using POST

public void insertFoto(){

    final String URL = "http://www.lineitopkal.com/genset/insert_site.php";

    final ProgressDialog loading = ProgressDialog.show(this,"Uploading...","Please wait...",false,false);
    StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            if(response.contains("success")) {
                loading.dismiss();
                Toast.makeText(getApplicationContext(),mbitmap01,Toast.LENGTH_SHORT).show();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            loading.dismiss();
            Toast.makeText(getApplicationContext(),"Data gagal disimpan",Toast.LENGTH_SHORT).show();
        }
    }){
        @Override
        protected Map<String, String> getParams(){
            Map<String, String> params = new HashMap<String, String>();
            params.put("lantai",mbitmap10);
            return params;
        }
    };

    stringRequest.setRetryPolicy(new DefaultRetryPolicy(0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    RequestQueue rq = Volley.newRequestQueue(this);
    rq.add(stringRequest);
}

I can't seem store all the images (the mbitmap10 one) in database with POST. Only the latest image was stored. Should I use array to store the image? If so how do I implement it? Or there is other way?

Arun J
  • 687
  • 4
  • 14
  • 27
BrenDonie
  • 85
  • 1
  • 10

1 Answers1

1

NOTE: This is general pseudo-code to demonstrate a concept and answer a general question

1) Put an empty array of bitmaps in your app:

Bitmap[] allBitmaps = new Bitmap[];

2) Each time that a new image is assigned to one of the image views, add it to the array in the position corresponding to the image view -- allBitmaps[2] = imageView2.getBitmap...

3) Then, when the user clicks submit, do something like this:

@Override
    protected Map<String, String> getParams(){
        Map<String, String> params = new HashMap<String, String>();

        // int paramNumber = 0;

        // for (bitmap : allBitmaps) {

        // params.put"paramNumber.toString()",bitmap);

        // paramNumber ++;

        // }

        return params;
    }
Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100