1. Are you ready for the Galaxy S20? Here is everything we know so far!

Retrieving preference in a url string

Discussion in 'Android Development' started by watsonink, Feb 16, 2011.

  1. watsonink

    watsonink Lurker
    Thread Starter

    final SharedPreferences prefs=PreferenceManager
    .getDefaultSharedPreferences(this);

    static String feedUrl = String.format("http://www.yourwebsite.com/android/objects/XML/AND.php?ID=%d", 22);


    the "22" should be a int variable from the preferences.

    I am saving the preferences correctly but can't concatenate the int with the below string.

    Any help would be appreciated...
     



    1. Download the Forums for Android™ app!


      Download

       
  2. miXer

    miXer Android Enthusiast

    If you don't know how to get a string from a preference, here goes:
    Code (Text):
    1. PreferenceManager.getDefaultSharedPreferences(this).getString("PreferenceKey", "DefaultReturnValueIfPreferenceKeyIsNotFound");
    Together this would be something like this:
    Code (Text):
    1. String feedUrl = "http://www.yourwebsite.com/android/objects/XML/AND.php?ID=" + PreferenceManager.getDefaultSharedPreferences(this).getString("PreferenceKey", "DefaultReturnValueIfPreferenceKeyIsNotFound");
     
  3. watsonink

    watsonink Lurker
    Thread Starter

    Thanks for responding miXer...

    My parser is a "static' string, is there a way to concatenate the preference into the string while keeping it as "static".

    I did try to replace the string you posted and it error'd stating "'(this)' can't be static"
     
Loading...
Similar Threads - Retrieving preference url
  1. Owen Lewis
    Replies:
    2
    Views:
    300
  2. Gary Olson
    Replies:
    9
    Views:
    699
  3. nurulaida
    Replies:
    0
    Views:
    418
  4. Earendil_Strife
    Replies:
    3
    Views:
    1,097
  5. iliji
    Replies:
    1
    Views:
    811
  6. Shadrachinthefurnace
    Replies:
    1
    Views:
    406
  7. DonHHI
    Replies:
    1
    Views:
    705
  8. Caterpillar123
    Replies:
    11
    Views:
    922
  9. LisaPisa
    Replies:
    5
    Views:
    735
  10. ltnielsen
    Replies:
    4
    Views:
    541

Share This Page

Loading...