Sunday 15 March 2015

javascript - How to populate webview in android with plain text from database and be able to handle newline characters -


I am new to Java and Android development, I am working on an application that includes access to basic programs in C and Includes simple GUI to read. And Java for students

I am trying to prepare a webview with a text file (a program in this case) which is preloaded in a certain column of my database.

I decided to use a scrollview because simultaneous scrolling and zooming are very difficult to implement. Customization was necessary for zooming, which was difficult for me to understand.

In this way I decided to use the webview because it is easily scrollable and only 1 line code is needed to apply zooming of text.

I have 2 problems:

1) Webview is unable to handle the new line using my current implementation. It tries to display all the text on the same line

2) It does not display "stdio.h", "stdlib.h", etc. Does .... basically all words with .h extension that are part of almost all programs. It is necessary to display them. I have tried the following 2 implementations (probably incorrectly): (String data, string data, string mimetype, string data, String data, string data, string data), string encoding, string history url)

My code is as follows:

  package com.example.uopengineering; Import java.io.UnsupportedEncodingException; Import Java.net.URLEncoder; Import android App Import android.content.Intent; Import android.database.Cursor; Import android.database.sqlite.SQLiteDatabase; Importroid.os.Bundle; Import android.webkit.WebView; See public class program activity & lt; X & gt; Activity {Private SQL Database Database; ExternalDbOpenHelper DBopenHelper; Private webview webview; Private Stable Last String DB_NAME = "umangdb.db"; Personal string queued; Private string programtext; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); SetContentView (R.layout.viewprogram); DbOpenHelper = New ExternalDbOpenHelper (this, DB_NAME); Database = dbOpenHelper.openDataBase (); Intent = getIntent (); Rowid = intent.getStringExtra ("myextra"); String query = "select * engg_table where _id =" + queued; Cursor myCursor = database.rawQuery (query, empty); MyCursor.moveToFirst (); Programtext = myCursor.getString (4); MyCursor.close (); Webview = (webview) find VVBIID (R. WEBV1); . WebView.getSettings () setBuiltInZoomControls (true); WebView.getSettings () setJavaScriptEnabled (true). //webView.loadData (programmatic, "text / html", "UTF-8"); Try {WebView.loadData (URLEncoder.encode (ProgramText, "UTF-8"). All ("\\ +", ""), "text / html", "utf-8"); //webView.loadDataWithBaseURL (empty, programtext, blank, query, blank); } Hold (unsupported encoding exception E) {// TODO auto generated blocking block e.printStackTrace (); }}}   

The related XML file (for layout puboose) is:

  & lt; Relative layout xmlns: android = "http://schemas.android .com / apk / res / android" xmlns: tools = "http://schemas.android.com/tools" Android: layout_width = "match_parent" Android: layout_height = "Match_parent" device: reference = "main activity" & gt; Android: Android: Android: Android: Scrollbars = "Vertical" /> & Lt; WebView Android: Android: Android: Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: layout_lagentleft = "true" Android: layout_linkPrinet = "true" /> & Lt; / RelativeLayout & gt;   

I went through other forums with similar questions, but was unable to find suitable solutions. One of these suggested that Use JavaScript to work around this problem . I know about javascript, is making assumptions in the web application form for my college project. Is it possible ?? If so, how do you suggest that I go about learning javascript and how do I want to implement it?

In addition to this, all ("\ +", "") is what? How is it removing unwanted characters? I am also not familiar with character encoding standards

Just change the content type in "text / plain" 4.4 did not work for me All content was still in a line What is the accepted answer in this stack overflow question, though it has been done:



No comments:

Post a Comment