2013-09-24 93 views
-4

夥計們我在android上工作,我有一個靜態變量,讓我們說「var」,如果它爲null,那麼如果語句被執行或者被執行,事情是,即使在我「var」不爲空,如果我重新啓動選項卡它按預期工作,有人啓發我。如果語句麻煩靜態變量

**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)); 

     }** 

    } 
} 
+6

請出示相關的代碼。 –

+1

我認爲這裏的語法需要清理一下,目前還不清楚,很難說出你的要求。 –

+0

這是否爲空檢查? – Cruncher

回答

0

變化if(ipath == "")if(ipath.isEmpty()),或者您也可以將其更改爲if(ipath.equals("")),我建議您閱讀This

+0

夥計們我想通了,我不得不使用onDestroy()方法,以便在退出前清理資源!!!! –