Search code examples
androidtextviewsettext

Multiple langues with textView and setText


I use a ImageAdapter to set a custom view with images and a caption. How can I support multiple langues for this text?

The text is now wet in the getView(...) method in the imageAdapter:

public View getView(int position, View convertView, ViewGroup parent) {
        View v;
        if (convertView == null) {
            LayoutInflater li = getLayoutInflater();
            v = li.inflate(R.layout.activity_main_icon, null);

            TextView tv = (TextView)v.findViewById(R.id.main_icon_text);
            tv.setText("**MENU TEXT**");

            ImageView iv = (ImageView)v.findViewById(R.id.main_icon_image);

            iv.setImageResource(mThumbIds[position]);
        } else {
            v = convertView;
        }

        return v;
    }

I guess the "MENU TEXT" should be set dynamically from res/Strings to support different langues, but how can I do this?

The GridView has four images that should have four different strings. E.g. "Add friend", "find friend", "Edit friend" and "Delete friend".


Solution

  • I recommend you to read this training:

    http://developer.android.com/guide/topics/resources/localization.html

    Then, your code should look like this:

    view.setText(getResources().getString(R.string.YOURSTRINGKEY));