'How can I change the language of the AlertDialog
I'm changing the language of everything and, I did end up stuck on the part that I need to change the AlertDialog.
And I think the thing that I'm getting wrong on it, is the ID stuff, I'm a bit lost on that part
Same on the other languages, but different languages
This is the string.xml and AlertDialog Code
<resources> <string name="app_name">Pntry</string>
<string name="add_item">Add Item</string>
<string name="enter_item_name">Enter Item Name</string>
<string name="enter_specifications">Enter Specifications</string>
<string name="select_expiry_date">Select Expiry Date</string>
<string name="update_item">Update Item</string>
<string name="filter">Filter</string>
<string name="action_filter">Sort by</string>
<string name="action_filter">All</string>
<string name="action_filter">Most outdated</string>
</resources>
public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.action_filter) {
final String[] listItems = new String[]{"All", "Most Outdated"};
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this)
.setTitle("Sort By")
.setSingleChoiceItems(listItems, checkedItem[0], (dialog, which) -> {
checkedItem[0] = which;
if (listItems[which].equals("All")) {
dialog.dismiss();
binding.recyclerView.setAdapter(new RecyclerViewAdapter(new DBHelper(this).getData(), this));
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
binding.fab.hide();
} else {
binding.fab.show();
}
}
});
} else if (listItems[which].equals("Most Outdated")){
dialog.dismiss();
binding.recyclerView.setAdapter(new RecyclerViewAdapter(new DBHelper(this).getDatewiseData(), this));
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
binding.fab.hide();
} else {
binding.fab.show();
}
}
});
}
});
AlertDialog customAlertDialog = alertDialog.create();
customAlertDialog.show();
}
return super.onOptionsItemSelected(item);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
