-3

伙计们,我正在研究 android,我有一个静态变量,比如说“var”,如果它为 null,那么如果执行了语句,或者执行了 else,事情就是,即使在我之后,“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));

        }**

    }
}
4

1 回答 1

0

更改if(ipath == "")为,if(ipath.isEmpty())或者您也可以将其更改为if(ipath.equals("")),我建议阅读

于 2013-09-24T17:22:16.857 回答