I am translating my app to Spanish and Arabic. I converted all the English Strings in the values file to the required language and that worked out very well.
My problem is that the activity names are still in the default language! As you see below, I used String activity1 = getResources().getString(R.string.activity1); I defined the 3 activity names in the values file (res/values-es/string.xml). For example my first activity has the id (activity1). For some reason this still does not work! Any suggestion or/and other reading materials!
package com.reportodor.mohamed;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends ListActivity{
String displayNames[] = { "Report Odor","Info","Contact Us",};
Class activities[] = {Report.class, Study.class, Contact.class};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, displayNames));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese = displayNames[position];
Class ourClass = activities[position];
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
//String activity1 = getResources().getString(R.string.activity1);
setTitle(getResources().getText(R.string.activity1));
setTitle("activity1 title"); //
}
}
I read the following and they were quite helpful: Accessing Resources Localizing with Resources