WebView.loadData utf-8 encoding Android
Try this solution:
String DATA = "Html text....bla bla bla. Hellou world! čšřžěéá";
String HEADERHTML =
"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">"
+"<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8">"
+"</head> <body>";
String FOOTERHTML = "</body></html>";
WebView mWebView.loadData(HEADERHTML+DATA+FOOTERHTML,"text/html; charset=UTF-8",null);
396LW NO topic_id
AD
Další témata ....(Topics)
onSaveInstanceState, onRestoreInstanceState , save preferences
int mCurrentPhotoIndex = 0;
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("photo_index", mCurrentPhotoIndex);
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
mCurrentPhotoIndex = savedInstanceState.getInt("photo_index");
super.onRestoreInstanceState(savedInstanceState);
}
// or save preferences for new start of Activity in onStop
//onCreate or onResume or onStart etc.
public void loadPreferences() {
SharedPreferences settings = getSharedPreferences(F.PREFERENCES_NAME, 0);
mCurrentPhotoIndex = settings.getInt("mCurrentPhotoIndex",mCurrentPhotoIndex);
// String_sOtazka = settings.getString("_sOtazka", _sOtazka);
}
// onStop
public void savePreferences() {
SharedPreferences settings = getSharedPreferences(PREFERENCES_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("mCurrentPhotoIndex", mCurrentPhotoIndex);
// String, boolean, float ...
// editor.putString("mButton1", mButton1.getText().toString());
editor.commit();
}
Map TreeMap key value pair, Map sort by key, Iterator for Map Java Android example.
MainClass.java
MainClass.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class MainClass {
public static void main(String[] arg) {
// english;germany dictionary
String[] arrayOfString = { "one;eine", "two;zwei", "three;drei", "four;vier" };
Map<String, String> map = new TreeMap<String, String>();
for(String s: arrayOfString){
String[] array = s.split(";");
String sKey ="", sValue="";
if(array.length > 1){
sKey = array[0]; sValue = array[1];
map.put(sKey, sValue);
}
}
List sortedByKeys=new ArrayList(map.keySet());
Collections.sort(sortedByKeys);
// iterate map
Set references = map.keySet();
Iterator it = references.iterator();
while (it.hasNext()) {
String key = (String) it.next();
String value = map.get(key);
System.out.println(key + " = " + value);
}
// or other example how iterate map
TreeSet<String> keys = new TreeSet<String>(map.keySet());
for (String key : keys) {
String value = map.get(key);
System.out.println(key + " = " + value);
}
// check if key exists
// if( map.containsKey("two")){
// System.out.print("two = " + map.get("two"));
// }
}
}
/*
four = vier
one = eine
three = drei
two = zwei
*/
- File->Project Structure Ctrl + Alt + Shift + S
- Select module and Dependencies Tab
- Click on + PLUS button (right upper corner)
- Select library
Click OK, OK
Log.e println needs a message error.
E/AndroidRuntime(330): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{b.paint/b.paint.MainActivity}: java.lang.NullPointerException: println needs a message
Try this code:
E/AndroidRuntime(330): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{b.paint/b.paint.MainActivity}: java.lang.NullPointerException: println needs a message
Try this code:
// Error
String s = null;
Log.e("bla", s); // !!! error Log.e println needs a message error.
// OK
String s = null;
Log.e("bla", s+""); // OK
If on Android emulator home button pressed.
Diagram of Activity lifecycle if button HOME pressed
// button home presssed
19:37:06.727: INFO/ActivityManager(60): Starting:
Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME]
flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher } from pid 60
19:37:06.807: INFO/onSaveInstanceState(339): onSaveInstanceState()
19:37:06.848: INFO/onPause(339): onPause()
19:37:07.968: INFO/onStop(339): onStop()
Diagram of Activity lifecycle if button HOME pressed
Editace: 2014-02-03 08:27:46
Počet článků v kategorii: 396
Url:webview-loaddata-utf-8-encoding-android