Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPedro Duarte
300 PointsHow to Convert the days of week in other Language italian, French or German?
public class DailyForecastActivity extends AppCompatActivity {
private Day [] mDays;
@BindView(android.R.id.list) ListView mListView;
@BindView(android.R.id.empty) TextView mEmptyTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily_forecast);
ButterKnife.bind(this);
// String[] dayOfWeek = {"Segunda-Feira", "Terça-Feira", "Quarta-Feira","Quinta-Feira",
// "Sexta-Feira", "Sabado"};
// ArrayAdapter<String> adapterone = new ArrayAdapter<String>(this,
// android.R.layout.simple_list_item_1, dayOfWeek);
Intent intent = getIntent();
Parcelable [] parcelables = intent.getParcelableArrayExtra(MainActivity.DAILY_FORESCAST);
mDays = Arrays.copyOf(parcelables, parcelables.length, Day[].class);
DayAdapter adapter = new DayAdapter(this, mDays);
mListView.setAdapter(adapter);
mListView.setEmptyView(mEmptyTextView);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
String dayOfWeek = mDays[position].getDayOfTheWeek();
String conditions = mDays [position].getSummary();
String highTemp = mDays [position].getTemperatureMax()+"";
String message = String.format("%s a maior temperatura, vai ser %s graus e serΓ‘ %s",
dayOfWeek, highTemp, conditions);
Toast.makeText(DailyForecastActivity.this, message, Toast.LENGTH_LONG).show();
}
});
}
}
1 Answer
Rares Conea
Courses Plus Student 15,000 PointsYou can define multiple strings.xml like the one you have in values.You can make one for italian language, one for french and so on and define a string array containing the days of the week in what language you want.When you install your app on a device the app will look at what language your phone is using and if in your values is an strings.xml defined for that language then the app will use the strings defined there.All the code that contains a string in your app should be defined as a string resourse in strings.xml and used with the name you gave it there
Pedro Duarte
300 PointsPedro Duarte
300 PointsThank you Rares Conea work well, also great tutorial this one, clarify my mind how work with Json :)!!!