How to gain the value of a structural resource on its behalf



  • Good night!

    There's a web page. This page is sent by GET. The request parameters are stored in the file strings.xml

    <string name="value">2af54c32</string>
    

    100% correct. But in the formation of the line, instead of the value that is stored in the resources, 2131099673♪ I mean, the string parameter somehow transformed into a decimal computation system. The page of the request is as follows:

    String site="http://example.com?id=";
    String url=site+R.string.value;
    

    How do we avoid this transformation? What's my mistake?



  • Resources in the adroide in the compilation are given the number of IDs, and some can be accessed. In your case, the resource was assigned to ID 2131099673

    For ease of use, these IDs in the code shall be used as R.ТИП_РЕСУРСА.ИМЯ РЕСУРСА (i.e. this public final static int Class field R)

    Special class techniques are required to receive resources. Context♪ In case of lines, you should use the method. getString(int ID):

    String value = context.getString(R.string.value);
    //или 
    //String value = context.getResources().getString(R.string.value);
    

    It should be noted that when the code is used in the activists, the indication of the class of context may be omitted because Activity It inherits itself. Context♪ I mean, just--

    String value = getString(R.string.value);
    //иди
    //String value = getResources().getString(R.string.value);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2