我正在使用以下代码比较从内部存储器中选择的imageview中设置的两个图像的路径,但是'generate'方法需要Intent数据,当与视图一起传递时会产生错误,表示“视图”从未使用过,例如。 public void generate(查看视图,Intent数据)。请提供解决方案,谢谢。
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 101);// change request
startActivityForResult(Intent.createChooser(intent1, "Select Picture"), 102); // change request code
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 101) {
// Get the url from data
Uri selectedImageUri = data.getData();
if ((null != selectedImageUri) ) {
// Get the path from the Uri
String path = getPathFromURI(selectedImageUri);
Log.i(TAG, "Image Path : " + path);
// Set the image in ImageView
((ImageView) findViewById(R.id.imgView)).setImageURI(selectedImageUri);
}
}else if(requestCode == 102){
Uri selectedImageUri1 = data.getData();
if ((null != selectedImageUri1)) {
// Get the path from the Uri
String path1 = getPathFromURI(selectedImageUri1);
Log.i(TAG, "Image Path : " + path1);
// Set the image in ImageView
((ImageView) findViewById(R.id.imgView2)).setImageURI(selectedImageUri1);
}
}
}
}
public void generate( View view ){
Uri selectedImageUri = data.getData();
String path = getPathFromURI(selectedImageUri);
Uri selectedImageUri1 = data.getData();
String path1 = getPathFromURI(selectedImageUri1);
if(path.contentEquals(path1)){
TextView myText = (TextView)findViewById(R.id.tv);
String myString = "same images";
myText.setText(myString);
}
else if(path1.length()%2==0) {
TextView myText = (TextView) findViewById(R.id.tv);
String myString = "repair completed";
myText.setText(myString);
}
else{
TextView myText = (TextView) findViewById(R.id.tv);
String myString = "repair not completed";
myText.setText(myString);
}
}