我有行列表。如果我想选择一个特定的行并且在"相机"的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;
}
});
}
任何人都可以帮我这个..? PLZ ...
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;
答案 0 :(得分:2)
所需的输出..实际上,onActivitResult()
中的图片浏览量引用了列表的最后一行。
<强>解决方案:强>
将图片文件路径存储在数组或列表中,并在onActivityResult()
中点击列表视图行的位置,然后从中调用adapter.notifyDatasetChnaged()
。
现在,在适配器的getView()
检查项目的位置,将您存储在onActivityResult()
的数组中,并在此条件下使用存储的图像文件路径Bitmap显示在imageview中。