2016-06-20 29 views
0

Iam開發一個簡單的應用程序,其中按下按鈕從圖庫中選擇適用於圖像查看框的圖像,但問題是如何記住每當我退出並重新打開時的圖像路徑應用程序相同的圖像應該出現在圖像視圖框中。如何記住適用於圖像查看框的圖像路徑

enter image description here

<ImageView 
       android:id="@+id/image1" 
       android:layout_width="100dp" 
       android:layout_height="200dp" 
       android:src="@drawable/index" 
       android:layout_margin="5dp" 

       /> 

回答

3

,你可以使用共享的首選項上的圖像選擇

SharedPreferences sharedpreferences = getSharedPreferences("ImagePrefs", Context.MODE_PRIVATE); 
Editor editor = sharedpreferences.edit(); 
editor.putString("imagePath", myImagePath); 
editor.commit(); 

那麼當你啓動應用程序多達

SharedPreferences sharedpreferences = getSharedPreferences("ImagePrefs", Context.MODE_PRIVATE); 
if(sharedpreferences.contains("imagePath")) // we have an image 
{ 
    String path = sharedpreferences.getString("imagePath") 
    //here set the image from the path 
} 
else 
{ 
    //no image was ever selected 
} 
+0

由於它的工作原理。但是較大的文件大小的圖像需要花費時間來加載,與較小的圖像相比較。 – rachit3dev