I have multiple menu files menu_language_en, menu_language_es…etc
I would like to load them using another variable, something like:
String lang="en";
inflater.inflate(eval("R.menu.language_menu_"+lang), menu);
Any idea??
Thanks
jo
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The right answer is to use resource sets, so you have a single filename in different directories based on language (e.g.,
res/menu/options.xml,res/menu-de/options.xml,res/menu-zh/options.xml, etc.). You, in your code, justinflate(R.menu.options, menu), and Android chooses the right language based on the user’s locale.If for some reason that solution is unsuitable, use
getResources().getIdentifier()to derive the resource ID given the name, then use that value with your call toinflate().