2014-08-29 63 views
0

我希望你能幫我解決我的簡單問題。我試圖從我的畫廊中選擇要在我的Imageview上顯示的圖像,但它可以正常工作,但在關閉我的應用程序後它會消失。請檢查我在下面找到的代碼。從應用關閉後,從圖庫中選擇的圖像從Imageview中消失

iv=(ImageView) rootView.findViewById(R.id.profpic); 
      iv.setOnClickListener(this); 



    private void showFileChooser() { 

     Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
     intent.setType("image/*"); 
     intent.addCategory(Intent.CATEGORY_OPENABLE); 

     try { 
      startActivityForResult(
        Intent.createChooser(intent, "Select a File to Upload"), 
        FILE_SELECT_CODE); 
     } catch (android.content.ActivityNotFoundException ex) { 
      // Potentially direct the user to the Market with a Dialog 
      Toast.makeText(getActivity(), "Please install a File Manager.", 
       Toast.LENGTH_SHORT).show(); 
     } 
    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     switch (requestCode) { 
      case FILE_SELECT_CODE: 
      if (resultCode == Activity.RESULT_OK) { 
       // Get the Uri of the selected file 
       Uri uri = data.getData(); 
       iv.setImageURI(uri); 
       Log.d(TAG, "File Uri: " + uri.toString()); 
       } 
      break; 
     } 
     super.onActivityResult(requestCode, resultCode, data); 
    } 

和我的XML:

<ImageView 
     android:id="@+id/profpic" 
     android:layout_width="113dp" 
     android:layout_height="113dp" 
     android:paddingRight="1dp" 
     android:src="@drawable/propic" /> 

我是新android開發任何幫助將不勝感激。提前致謝!

+0

當活動被破壞時,圖像也是如此 – Eenvincible 2014-08-29 03:38:13

回答

0

一旦你上傳圖片,它不會永遠保留它們。您需要保留所選圖像的路徑Sqlite databaseSharedPreference。然後在啓動您的活動時,您需要使用圖像路徑來加載到ImageView

+1

感謝您的信息。我會盡力對此進行更多的研究。 – DEADPOOL 2014-08-29 03:40:55

相關問題