-1

Here's a sample code:

toastMessage = "Data added successfully";
...  
Toast.makeText(this, toastMessage, Toast.LENGTH_SHORT).show();

In this way, users only can interact with the English language, What can I do, if I wanted to show messages like above to user base on their language preferences (e.g. German or France) in android.

Thanks.

Pedram
  • 557
  • 5
  • 17
  • 4
    https://developer.android.com/training/basics/supporting-devices/languages.html – Steve Smith Apr 03 '17 at 14:40
  • 3
    Toast support adding strings resource value instead of String object. Even if it wouldn't, you should just take the resource via Context.getString(id) method. – mhenryk Apr 03 '17 at 14:40
  • I know my question was silly back then. But I think this is a community for helping each other and I don't know why some gave this question negatively. sometimes we search and try ... but in the wrong way. Note that! – Pedram May 25 '19 at 06:29

1 Answers1

1

You can use strings from string.xml (and all other resources) in the code.

Toast.makeText(this, R.string.string_id, Toast.LENGTH_SHORT).show();

or for other places where you can't use id directly:

context.getString(R.string.string_id)
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98