Xin chào Tôi đang phân tích cú pháp xml và sau đó tải nó vào chế độ xem web, sau khi phân tích cú pháp, tôi đang tạo bốn chuỗi để tôi có thể nối tất cả chuỗi vào một chế độ xem. Tôi có thể nhận được hai chế độ xem trên chế độ xem web nhưng không thể xem hai chuỗi đầu tiên.Làm cách nào để chuyển chuỗi html vào webview trên android
Xin giới thiệu cho tôi mã của tôi, tôi đang đi sai ở đâu và cách chính xác để nhận các chuỗi html được định dạng trên chế độ xem web là gì. Xin vui lòng xem mã của tôi và giúp tôi giải quyết vấn đề này.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
String chapterTitle = "";
String SubChapterTitle="";
String chapterIntro ="";
String chapterContent="";
View view = convertView;
if (convertView == null) {
// view = inflater.inflate(resourceid, null);
view = getLayoutInflater().inflate(R.layout.webviewitem, null);
}
synchronized (view) {
WebView wv = (WebView) view.findViewById(R.id.contentWebView);
WebSettings settings = wv.getSettings();
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setJavaScriptEnabled(true);
settings.setDefaultZoom(ZoomDensity.FAR);
// wv.setBackgroundColor(0);
wv.setVerticalScrollBarEnabled(false);
wv.setHorizontalScrollBarEnabled(false);
/*String txtChapTitle = Intro.book.getsecretList().get(position)
.getChtitle().toString();*/
if (!(Intro.book.getsecretList().get(position).getChtitle()
.toString().equals(""))){
chapterTitle = "<b><fontSize=4>"+Intro.book.getsecretList().get(position)
.getChtitle().toString()+"</font></b>";
}
if (!(Intro.book.getsecretList().get(position)
.getSubtitle() == null)) {
SubChapterTitle = "<b><fontSize=4>"+Intro.book.getsecretList().get(position)
.getSubtitle().toString()+"</font></b>";
}
if (!(Intro.book.getsecretList().get(position)
.getIntro() == null)) {
chapterIntro = "<b><fontSize=2>"+Intro.book.getsecretList().get(position)
.getIntro().toString()+"</font></b>";
}
if (!(Intro.book.getsecretList().get(position)
.getContent() == null)) {
chapterContent = "<fontSize=2>"+Intro.book.getsecretList().get(position)
.getContent().toString()+"</font>";
}
StringBuilder content = new StringBuilder();
content.append(chapterTitle+SubChapterTitle+chapterIntro+chapterContent);
JsInterface Jsi = new JsInterface();
Jsi.wordDef = content ;
Log.v("Content", "" +content);
wv.addJavascriptInterface(Jsi, "interfaces");
wv.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
view.setHapticFeedbackEnabled(false);
}
});
wv.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url,
String message, JsResult result) {
return super.onJsAlert(view, url, message, result);
}
});
wv.loadUrl("file:///android_asset/wordview.html");
}
return view;
}
}
Tôi có thể lấy chapterIntro và chaptercontent trên chế độ xem web nhưng không phải là hai chuỗi đầu tiên giúp bạn bè.
tôi đã cố gắng với điều đó, vẫn không xảy ra cũng đã cố gắng với loadbaserul – cavallo
là nghĩa vụ phải làm việc với một chuỗi chứa javascript? Nó không hoạt động cho tôi – Edu
nó phải là 'webView.loadData (yourData," văn bản/html; charset = utf-8 "," UTF-8 ");" – Jaroslav