@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_adharFrontUploadId:
pickImage();
loadAdharFrontImage();
break;
case btn_adharBackUploadId:
pickImage();
loadAdharBackImage();
break;
}
}
它显示来自设备的两个不同的图像。我写的方法如下
private void loadAdharBackImage() {
new Thread() {
public void run() {
while (i++ < 1000) {
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
iv_adharBack.setImageBitmap(decodedWebP);
}
});
sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
}
private void loadAdharFrontImage() {
new Thread() {
public void run() {
while (i++ < 1000) {
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
iv_adharFront.setImageBitmap(decodedWebP);
}
});
sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
}
当我通过点击第一按钮选择第一图像时,它像往常一样加载第一图像视图,但当我点击第二按钮时,它立即将第一选择的图像加载到第二图像视图中,并且当选择第二图像时,第一图像视图也变为第二选择的图像。请给我一个解决方案。我对android和编程很陌生。如有任何帮助,将不胜感激
感谢大家的支持。。。最后我得到了答案。不需要使用我的问题中提到的runnable。在这里,我可以制作代码来获取不同imageViews的图像。再次感谢
@Override
public void onClick(View v) {
switch (v.getId()) {
case btn_applAdharFrontUploadId:
pickImage(1);
break;
case btn_applAdharBackUploadId:
pickImage(2);
break;
}
}
在这里,我可以使用相同的代码来压缩我的图像,并将它们加载到imageViews
private void pickImage(int i) {
Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
pickImageIntent.setType("image/*");
startActivityForResult(Intent.createChooser(pickImageIntent, "Select Picture"), i);
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
assert data != null;
Uri imageUri = data.getData();
InputStream is = null;
try {
assert imageUri != null;
is = getContentResolver().openInputStream(imageUri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
assert is != null;
BufferedInputStream bufferedInputStream = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bufferedInputStream);
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.WEBP, 60, out);
Bitmap decodedImage = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
switch (requestCode){
case 1:
iv_ApplAdharFront.setImageBitmap(decodedImage);
break;
case 2:
iv_ApplAdharBack.setImageBitmap(decodedImage);
break;