The fragment has a static factory method newInstance . It creates a Bundle order to pass the int parameter. For the putInt() method and the further extraction I want to use a string - a tag from resources, but I can't get it using the Resources.getSystem().getString method Resources.getSystem().getString How can I get a string from resources in this situation? It seems irrational to store a static field with a tag
- In this case, no line from the resources is needed. Make a simple string constant. Rows from resources are usually used where the user sees them and they can be localized. For the name of extra resources is unnecessary. - eugeneek 2:53 pm
|
2 answers
In this particular case, just the use of resources would be irrational. It is enough to declare a simple string constant and use it as a tag:
public static final String TAG = "some_tag"; If you still want a string from resources, then just pass the Resources to your method factory, along with the rest of the parameters:
public static SomeFragment newInstance(Resources res, int id) { String tag = res.getString(R.string.some_id); ... } |
Why Resources.getSystem() ?
There are no lines of yours.
Returns to global system resources (no application resources)
Just Resources.getString(int id) and everything will be if the id correct.
Updated
Without access to Context the application resources are not accessible. So either a constant, which is most often used, or Context as the parameter newInstance .
- From static context it will not be possible to call Resources.getString (int id) - Clarence
|