What does this method accomplish?
URL aURL = new URL(myRemoteImages[position]);
myRemoteImages is a String list, with 4 different variables. And position is a
int position;
EDIT:
So if there anyway i could take the place of position with possibly something else?
possibly
myRemoteImages{1,2,3,4};?
EDIT: i am using this to get the the URI for each image in the cahce…
public void getImagesfromCache(){
ImageAdapter adapter = new ImageAdapter();
String[] cachImages = myRemoteImages;
try {
URL aURL2 = null;
aURL2 = new URL(cachImages[position]);
URI imageCacheUri = null;
try {
imageCacheUri = aURL2.toURI();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(new File(new File(this.getApplicationContext().getCacheDir(), "thumbnails"),"" + imageCacheUri.hashCode()).exists()){
Log.v("FOUND", "Images found in cache! Now being loaded!");
String cacheFile = this.getApplicationContext().getCacheDir() +"/thumbnails/"+ imageCacheUri.hashCode();
ImageView i = new ImageView(this.getApplicationContext());
FileInputStream fis = null;
try {
fis = new FileInputStream(cacheFile);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap bm = BitmapFactory.decodeStream(fis);
i.setImageBitmap(bm);
putBitmapInDiskCache(imageCacheUri, bm);
Log.v("Loader", "Image saved to cache");
((Gallery) findViewById(R.id.gallery))
.setAdapter(new ImageAdapter(MainMenu.this));
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
As you see where position is used, how could i go about another way to return the URL’s to get the images in the cache?
Could i possibly store each URI in a SharePreference and fetch them in onCreate()??
It creates a URL object, from the url string specified by the element within the array (myRemoteImages) at the specific position.
The following syntax creates a URL object
The following syntax gets the String value at the specified position
So, to get a URL for each position, you could do
It would be far better though to have an array of URLs though. So it would be
With this array of URLs, even though you know there are only 4 images, it can be extended easily without having to change any code. Hard coding is VERY bad, and will usually lead to errors in the long run.