How to set different locales in android
- create new folder with values in resources folder in project with extension your language code
For example:
My language is Czech (cs)
I have to create the folder values-cs in res folder
Into every values folder put strings.xml file
Translate every string from values folder into your locale.
If user selected your locale in device settings, application selects a string from the correct (proper) folder.
For example:
My language is Czech (cs)
I have to create the folder values-cs in res folder
// for locale English is default
/MyProject/res/values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">App English default</string>
<string name="action_settings">Settings English default</string>
<string name="hello_world">Hello world</string>
</resources>
// for locale Czech (cs)
/MyProject/res/values-cs
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Aplikace česky cs</string>
<string name="action_settings">Nastavení česky</string>
<string name="hello_world">Ahoj světe!</string>
</resources>
// for locale English US (r is region)
/MyProject/res/values-en-rUS
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">App English Us locale</string>
<string name="action_settings">Settings English Us locale</string>
<string name="hello_world">Hello world from USA :)</string>
</resources>
Into every values folder put strings.xml file
Translate every string from values folder into your locale.
If user selected your locale in device settings, application selects a string from the correct (proper) folder.
396LW NO topic_id
AD
Další témata ....(Topics)
You can use for, do while, while cycle for example:
public void myFunction(){
for (int i = 0; i < 1; i++) {
// some code
int c = 10;
if(c==10)
break; // goto stop; in C++
} // end of for
// stop: // break moved process to end of for
// next code
}
Best of SQLite explorer and admin download for SQLite 2.x and SQLite 3.x in separated folders.
Download Explorers SQLite 2.x and SQLite 3.x in separated folders
Download Explorers SQLite 2.x and SQLite 3.x in separated folders
Call findViewById from onCreateView
res\layout
activity_main.xml
fragment_main.xml
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.containerMoje, new PlaceholderFragment()).commit();
}
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
if (container == null) {
return null;
}
TextView mText;
mText = (TextView)rootView.findViewById(R.id.idText);
mText.setText("Hello from fragment_main");
return rootView;
}
}
}
res\layout
activity_main.xml
<FrameLayout xmlns:android="//schemas.android.com/apk/res/android"
xmlns:tools="//schemas.android.com/tools"
android:id="@+id/containerMoje"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="cz.okhelp.autoskola.MainActivity"
tools:ignore="MergeRootFrame" />
fragment_main.xml
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android"
xmlns:tools="//schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="cz.okhelp.autoskola.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/idText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
public boolean isConnected() {
try {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo().isConnectedOrConnecting();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("isConnected", e.getMessage());
Toast.makeText(getApplicationContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
return false;
}
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.my_package/com.example.my_package.MainClass}; have you declared this activity in your AndroidManifest.xml?
Is MainClass.java in AndroidManifest as a activity ?
AndroidManifest.xml example
Is MainClass.java in AndroidManifest as a activity ?
AndroidManifest.xml example
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="//schemas.android.com/apk/res/android"
package="com.example.my_packag"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainClass"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Editace: 2014-02-12 19:52:37
Počet článků v kategorii: 396
Url:how-to-set-different-locales-in-android