android listView 子控件事件错行处理
2012-11-16 15:34:01 来源:WEB开发网
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
final int arg2, long arg3) {
// TODO Auto-generated method stub
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("提示");
builder.setMessage("确认删除图片吗?");
builder.setIcon(R.drawable.icon);
builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if(!bitPhoto.equals("") || bitPhoto != null)
{
String[] bitPhotoStr = bitPhoto.split(",");
bitPhoto = "";
for (int i = 0; i < bitPhotoStr.length; i++) {
if(arg2 == i)
continue;
if(bitPhoto.equals("") || bitPhoto == null)
bitPhoto = bitPhotoStr[i];
else
bitPhoto = bitPhoto + "," + bitPhotoStr[i];
}
imageItem.remove(arg2);
if(holderDatas.size() > index)
{
holderDatas.get(index).setImageList(imageItem);
holderDatas.get(index).setStrBitPhoto(bitPhoto);
patrolReportBackDatas.get(index).setPhotos(bitPhoto);
// if(patrolReportBackData != null && changed != false)
// patrolReportBackData.setPhotos(bitPhoto);
}
ImageAdapter adapter = new ImageAdapter(imageItem,context);
photograph.setAdapter(adapter);
}
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//取消按钮事件
}
});
builder.show();
return false;
}
};
private void initPicture(String pictureName) {
// TODO Auto-generated method stub
String imagepath = Environment.getExternalStorageDirectory() + "/MOMSPHOTO/" + pictureName;
String byte64Str = getImageBinary(imagepath);
if(bitPhoto.equals("") || bitPhoto == null)
bitPhoto = byte64Str;
else
bitPhoto = bitPhoto + "," + byte64Str;
if(holderDatas.size() > index)
{
holderDatas.get(index).setStrBitPhoto(bitPhoto);
patrolReportBackDatas.get(index).setPhotos(bitPhoto);
// if(patrolReportBackData != null && changed != false)
// patrolReportBackData.setPhotos(bitPhoto);
}
}
/**
* 图片转换成字符串[BASE64]
*
* @return
*/
public String getImageBinary(String path) {
System.out.println("path--->" + path);
try {
Bitmap bitmap = getBitmapFromFile(new File(path),640,640);//scalePicture(path,640,640);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG,100,baos);
String uploadBuffer = new String(Base64.encodeToString(baos.toByteArray(),Base64.DEFAULT));
baos.flush();
baos.close();
System.out.println("图片信息转换成字符串为:---->" + uploadBuffer);
return uploadBuffer;
}
更多精彩
赞助商链接