0

How to get string values using this,right now it return integer value.

 getApplicationContext(),getResources().getIdentifier("Please_Try_Again_"+nativeLocaleSymbol, "string", getPackageName());

2 Answers 2

2

getIdentifier returns the resource identifier that why it is an int. Using the id you can get the resource

 int resId = getApplicationContext().getResources().getIdentifier("Please_Try_Again_"+nativeLocaleSymbol, "string", getPackageName());
 getApplicationContext().getResources().getString(resId)
Sign up to request clarification or add additional context in comments.

1 Comment

it's work but i have modified it getApplicationContext().getResources().getString(getApplicationContext().getResources().getIdentifier("loading_"+nativeLocaleSymbol, "string", getPackageName()));
0

You can add this code to your application

    /**
     * Returns value of String from Android String identifier
     * 
     * @param id
     *            Android String identifier
     * @return Value of String identifier if argument is valid Android String
     *         identifier, same String passed in argument if not.
     */
    public static String getStringByFullIdentifier(final Context context,
            final String fullId) {
        String ret = fullId;
        final String id = StringHelper.getStringIdentifier(fullId);
        if (id != null) {
            ret = StringHelper.getStringByName(context, id);
        }
        return ret;
    }

    /**
     * Returns string resource by name. Consider using
     * {@link #getStringByName(String)} instead.
     */
    public static String getStringByName(final Context context,
            final String name) {
        final int intId = context.getResources().getIdentifier(name, "string",
                context.getPackageName());
        String result = null;
        try {
            result = context.getString(intId);
        } catch (final NotFoundException e) {
            result = name;
        }
        return result;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.