伙计我正在研究android,我有一个静态变量,让我们说“var”,如果它是null然后如果语句被执行或者执行,那么事情就是,即使在我“var”不为null之后,如果我重新启动选项卡,它按预期工作,有人启发我。
**protected static String ipath="" , ipath1;**
protected OnClickListener selimg = new OnClickListener() // for first image
{
@Override
public void onClick(View vw)
{
// TODO Auto-generated method stub
Intent i = new Intent(
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
};
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
ImageView imageView1 = (ImageView) findViewById(R.id.imageView2);
**if(ipath == "")
{
ipath=picturePath;
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
else
{
ipath1=picturePath;
imageView1.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}**
}
}
答案 0 :(得分:0)
将if(ipath == "")
更改为if(ipath.isEmpty())
,或者您也可以将其更改为if(ipath.equals(""))
,我建议您阅读This