I have this Code to Capture a image and Display it back in ListView
onclick of the listitem i can capture image and save to image View, but how can get onlthe left of the list item?
public class ShootList extends ListActivity implements OnItemClickListener {
String[] listItems = {"HeadShot", "BodyShot ", "ExtraShot", "Video Take1", "Video Take2", "Video Take3", };
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, listItems));
ListView shot = getListView();
shot.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int Position, long arg3) {
// TODO Auto-generated method stub
int P = Position;
switch ( P ) {
case 0:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 1);
break;
case 1:
AlertDialog.Builder alertbox1 = new AlertDialog.Builder(this);
alertbox1.setMessage("BodyShot").show();
break;
case 2:
AlertDialog.Builder alertbox2 = new AlertDialog.Builder(this);
alertbox2.setMessage("ExtraShot").show();
break;
case 3:
Intent Take1 = new Intent("android.media.action.VIDEO_CAPTURE");
startActivityForResult(Take1, 0);
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.img);
mImg.setImageBitmap(b);
// save image to gallery
String timestamp = Long.toString(System.currentTimeMillis());
MediaStore.Images.Media.insertImage(getContentResolver(), b, timestamp, timestamp);
}
}
}
NOTE: you should always include an explanation of your question, not just code.
If you want an icon with your list item, then you need to include it in your list item’s layout xml file, which will look something like this:
Then, you will need to create a custom list adapter and override the getView() method to set the image and text fields. For all your list view needs, go here