I just need to know if it's english go to url2 and if it's spanish url . I have some layouts with strings in Spanish and English and I know how to use them to exit depending on the user's language, but since it's a URL, I'm not able to make it go to one URL or another.
I have tried putting a string and comparing it or assigning numbers to it but nothing, I am not able. The solution would be if(es ingles) { go to url2} if not (spanish}
public class Competidores extends android.support.v4.app.Fragment {
WebView appWeb;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.four_tab, container, false);
String url = " https://rudeboysapp.wordpress.com/";
String url2 = " https://rudeboysappenglish.wordpress.com/";
if(l7 == "es") {
appWeb = (WebView) v.findViewById(R.id.webView);
//Habilitamos el javaScript y el zoom
appWeb.getSettings().setJavaScriptEnabled(true);
// appWeb.getSettings().setBuiltInZoomControls(true);
//Cargamos el enlace definido
appWeb.loadUrl(url);
//Este método es para que el navegador se quede en nuestra aplicación
appWeb.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
}else {
appWeb = (WebView) v.findViewById(R.id.webView);
//Habilitamos el javaScript y el zoom
appWeb.getSettings().setJavaScriptEnabled(true);
// appWeb.getSettings().setBuiltInZoomControls(true);
//Cargamos el enlace definido
appWeb.loadUrl(url2);
//Este método es para que el navegador se quede en nuestra aplicación
appWeb.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
}
return v;
}
You must retrieve the system language using the Locale object and its getDefault() method:
Depending on what it gives you, it will be one language or another. For example, American English is "en_US" while British English is "en_EN" and Spanish from Spain is "es_ES"... and so on. If you look closely, the first two acronyms are always the language and the next two after the "_" are the country.
If you only care about the language regardless of the country, you have the getLanguage() method:
This object also has other methods that may be useful to you, such as: