我有行列表。如果我想选择特定行并在“相机”按钮的 onclick 事件中,应将捕获的图像添加到该选定行。但我的问题是捕获的图像添加到最后一行。
private void getlist(final ArrayList<Exceptions> exceptionRowsList2) {
lv1.setAdapter(new ArrayAdapter<Exceptions>(getApplicationContext(),
R.layout.damagerow, exceptionRowsList2) {
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
final View row;
if (null == convertView) {
row = mInflater.inflate(R.layout.damagerow, null);
} else {
row = convertView;
}
TextView errorCode = (TextView) row.findViewById(R.id.error_code);
TextView errorCodeval = (TextView) row.findViewById(R.id.error_code_val);
TextView description = (TextView) row.findViewById(R.id.desc);
TextView descriptionVal = (TextView) row.findViewById(R.id.desc_val);
damage1 = (ImageView) row.findViewById(R.id.damageimage1);
damage2 = (ImageView) row.findViewById(R.id.damageimage2);
damage3 = (ImageView) row.findViewById(R.id.damageimage3);
damage4 = (ImageView) row.findViewById(R.id.damageimage4);
damage1.setImageResource(R.drawable.damage_bg_default);
damage2.setImageResource(R.drawable.damage_bg_default);
damage3.setImageResource(R.drawable.damage_bg_default);
damage4.setImageResource(R.drawable.damage_bg_default);
errorCode.setTextColor(Color.BLACK);
errorCodeval.setTextColor(Color.BLACK);
description.setTextColor(Color.BLACK);
descriptionVal.setTextColor(Color.BLACK);
errorCode.setText("Error Code: ");
errorCodeval.setText(""
+ exceptionRowsList2.get(position).getAreaCode() + "-"
+ exceptionRowsList2.get(position).getTypeCode() + "-"
+ exceptionRowsList2.get(position).getSeverityCode()
.toString());
description.setText("Description: ");
descriptionVal.setText(""
+ exceptionRowsList2.get(position).getAreaDesc() + " - "
+ exceptionRowsList2.get(position).getTypeDesc() + " - "
+ exceptionRowsList2.get(position).getSeverityDesc());
row.setBackgroundResource(R.drawable.error_detail_list_bg);
row.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
row.setBackgroundResource(R.drawable.select_damage);
exceptionRowsList2.get(position).setTakeImage(true);
exceptionRowsList2.get(position).setDelete(true);
}
});
return row;
}
});
}
谁能帮我这个..?请...
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
if (resultCode == RESULT_OK) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
//3
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
//uuid = UUID.randomUUID().toString();
String imageFile = timeStamp + ".png";
Log.w("Images From Sdcard", imageFile);
damageList.add(imageFile);
File file = new File(Environment.getExternalStorageDirectory()+File.separator + imageFile);
try {
file.createNewFile();
FileOutputStream fo = new FileOutputStream(file);
//5
fo.write(bytes.toByteArray());
fo.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String pathName = "/sdcard/" + imageFile;
Resources res = getResources();
Bitmap bitmap = BitmapFactory.decodeFile(pathName);
bitmap = Bitmap.createScaledBitmap(bitmap, 100, 100, true);
BitmapDrawable bd = new BitmapDrawable(res, bitmap);
switch(strDamages.length) {
case 0 :
damage1.setImageBitmap(bitmap);
break;
case 1 :
damage2.setImageBitmap(bitmap);
i++;
break;
case 2 :
damage3.setImageBitmap(bitmap);
i++;
break;
case 3 :
damage4.setImageBitmap(bitmap);
i++;
break;
}
objDamages = damageList.toArray();
strDamages = Arrays.copyOf(objDamages, objDamages.length, String[].class);
} else if (resultCode == RESULT_CANCELED) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(
this).setMessage("Camera Activity Cancelled.")
.setTitle("status");
dialogBuilder.setPositiveButton("OK",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
return;
}
});
dialogBuilder.create().show();
} else {
// Toast.makeText(this, "Picture was not taken",
// Toast.LENGTH_SHORT);
}
}
}
相机按钮点击事件..
case R.id.camera_btn:
if(exceptionRowsList.isEmpty()){
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(
this).setMessage("No Exception Added")
.setTitle("Alert");
dialogBuilder.setPositiveButton("OK",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
return;
}
});
dialogBuilder.create().show();
}else{
for (Exceptions exceptions : ede) {
if(exceptions.getDelete()){
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
break;
}else{
//getlist(ede);
//exceptionRowsList.add(exceptions);
}
}
}
break;