tags:

views:

84

answers:

0

i am working on a app for a android , i have to take three photos by activating android camera and save it in particular location in sd memory and assign it to them as thumbnails, 1st shot working fine and coming to second photo it is not saving and not assigning to the thumbnail.

Please let me know how can i take multiple photos on click ListView items saving and retriving them?

       public class ShootList extends ListActivity implements OnItemClickListener {



private static final String ICON = "icon";
private static final String NAME = "name";
private static final String PROG = "prog";
int i = 0;

private static final String[] PARAM = { ICON, NAME, PROG };
private List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();


  String[] listItems = {"HeadShot", "BodyShot ", "ExtraShot", "Video Take1", "Video Take2", "Video Take3", }; 
     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.shoot);

            ImageView pgrs = (ImageView) findViewById(R.id.progress);

            //setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, listItems));

            for(String p :listItems)
             {

                 addItem(list, R.drawable.image, listItems[i]);

                 i++;

             }



            SimpleAdapter notes = new SimpleAdapter(this, list,
                    R.layout.row, PARAM, new int[] { R.id.image, R.id.name });
            setListAdapter(notes);
            ListView shot = getListView();
            shot.setOnItemClickListener(this);
     }


        public void addItem(List<Map<String, Object>> data, int icon, String
        name) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(ICON, icon);
        map.put(NAME, name);

        data.add(map);

        }

public void onItemClick(AdapterView<?> arg0, View arg1, int Position,
            long arg3) {


        int P = Position;


        switch ( P ) {
        case 0:
            Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
            startActivityForResult(intent, 1);
            break;
        case 1:
            Intent intent2 = new Intent("android.media.action.IMAGE_CAPTURE");
            startActivityForResult(intent2, 2);
            break;
        case 2:
            AlertDialog.Builder alertbox2 = new AlertDialog.Builder(this);
            alertbox2.setMessage("ExtraShot").show();
            break;
        case 3:

            AlertDialog.Builder alertbox3 = new AlertDialog.Builder(this);
            alertbox3.setMessage("Take1").show();
            break;
        case 4:
            AlertDialog.Builder alertbox4 = new AlertDialog.Builder(this);
            alertbox4.setMessage("Take2").show();
            break;
        case 5:
            AlertDialog.Builder alertbox5 = new AlertDialog.Builder(this);
            alertbox5.setMessage("Take3").show();
            break;

        default:

            break;
    }

    }
public void onActivityResult(int requestCode, int resultCode, Intent data) {

 super.onActivityResult(requestCode, resultCode, data);


    int i;

// if Activity was canceled, display a Toast message

 if (resultCode == RESULT_CANCELED) {
 Toast toast = Toast.makeText(this,"camera cancelled", 10000);
 toast.show();
 return;
 }

// lets check if we are really dealing with a picture

 if (requestCode == 1 && resultCode == RESULT_OK)
 {

     Bundle extras = data.getExtras();
        Bitmap b = (Bitmap) extras.get("data");
        //setContentView(R.layout.main);

        ImageView mImg;
        mImg = (ImageView) findViewById(R.id.image);
        mImg.setImageBitmap(b);
   // save image to gallery
     String timestamp = Long.toString(System.currentTimeMillis());
     MediaStore.Images.Media.insertImage(getContentResolver(), b, timestamp, timestamp);

 }



 if (requestCode == 2 && resultCode == RESULT_OK)
 {

        Bundle extras = data.getExtras();
        Bitmap c = (Bitmap) extras.get("data");
        //setContentView(R.layout.main);

        ImageView nImg;
        nImg = (ImageView) findViewById(R.id.image);
        nImg.setImageBitmap(c);
   // save image to gallery
     String timestamp = Long.toString(System.currentTimeMillis());
     MediaStore.Images.Media.insertImage(getContentResolver(), c, timestamp, timestamp);

 }

}

}