I Can Only Get Part Of A Url (link) And Put Into String In Android?
[Solved] - I need to resolve the problem below Ok I wasn't really sure how to word this question, but basically what I want to do is, I got a url from a RSS feed in android, and I
Solution 1:
Do it like this
String url = "http://www.prsn.uprm.edu/Spanish/Informe_Sismo/myinfoGeneral.php?id=20161206012821";
String[] array = url.split("id=");
String id = array[1];
String urlToLoad = "http://shake.uprm.edu/~shake/archive/shake/"+id+"/download/tvmap.jpg"
Glide.with(context).load(urlToLoad).into(holder.Thumbnail);
Then use this id where you want to use
Solution 2:
You can achieve that making a substring of the number you want to find and then appending that to the string you need.
The code would be as follows:
//the original String
String somestring = "http://www.prsn.uprm.edu/Spanish/Informe_Sismo/myinfoGeneral.php?id=20161206012821";
//save the index of the string '=' since after that is were you find your number, remember to add one as the begin index is inclusiveint beginIndex = somestring.indexOf("=") + 1;
//if the number ends the string then save the length of the string as the end, you can change this index if that's not the caseint endIndex = somestring.length();
//Obtain the substring using the indexes you obtained (if the number ends the string you can ignore the second index, but i leave it here so you may use it if that's not the case)
String theNumber = somestring.substring(beginIndex,endIndex);
//printing the number for testing purposes
System.out.println("The number is: " + theNumber);
//Then create a new string with the data you want (I recommend using StringBuilder) with the first part of what you want
StringBuilder sb=new StringBuilder("http://shake.uprm.edu/~shake/archive/shake/");
// add the number
sb.append(theNumber);
//then the rest of the string
sb.append("/download/tvmap.jpg");
//Saving the String in a variable
String endResult = sb.toString();
//Verifying end result
System.out.println("The end result is: "+endResult);
After that you can put the String into Glide I hope It was clear and well explained.
Post a Comment for "I Can Only Get Part Of A Url (link) And Put Into String In Android?"