2013-03-29 4 views
1

J'essaie de stocker la page html dans db comme chaîne. Alors j'ai besoin d'afficher cette page dans webview. ici je colle mon code pls aide moi ....... Comment stockez-vous une page html dans une base de données sqlite dans android? J'ai essayé pour convertir la page html en tableau bytes pour stocker dans la base de données. S'il vous plaît aidez-moi comment stocker insert dans db puis ouvrez cette charge dans WebView ...comment afficher la page html de db

public class AndroidOpenDbHelper extends SQLiteOpenHelper { 
    public static final String DB_NAME = "html_db"; 
    public static final int DB_VERSION = 1; 
    public static final String TABLE_NAME = "html_table"; 
    public static final String COLUMN_NAME_ID = "html_id_column"; 
    public static final String COLUMN_NAME_PAGE = "page_column"; 


    public AndroidOpenDbHelper(Context context) { 
     super(context, DB_NAME, null, DB_VERSION); 
     // TODO Auto-generated constructor stub 
    } 

    @Override 
    public void onCreate(SQLiteDatabase db) { 
     // TODO Auto-generated method stub 
     //"create table if not exists TABLE_NAME (BaseColumns._ID integer primary key autoincrement, FIRST_COLUMN_NAME text not null, SECOND_COLUMN_NAME integer not null);" 
       String sqlQueryToCreateTable = "create table if not exists " + TABLE_NAME + " (" + BaseColumns._ID + " integer primary key autoincrement, " 
                     + COLUMN_NAME_PAGE + " HTML STRING, " 
                     ; 

       // Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data. 
       db.execSQL(sqlQueryToCreateTable); 

    } 

    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
     // TODO Auto-generated method stub 
     if(oldVersion == 1 && newVersion == 2){ 
      // Upgrade the database 
     }  
    } 

    } 

et ce mon code pour afficher la page.

public class MainActivity extends Activity { 
    WebView browser; 
    private static String inp; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     browser=(WebView)findViewById(R.id.w1); 




    } 


    private void loadTime(SQLiteDatabase db) { 
     // TODO Auto-generated method stub 

     browser.getSettings().setJavaScriptEnabled(true); 

        browser.loadDataWithBaseURL("x-data://base",inp,"text/html", "UTF-8",null); 

     // browser.loadUrl(inp); 

    } 
    public static String main(String args[]) throws FileNotFoundException { 
     FileInputStream fis = new FileInputStream("D:/mo.html"); 
      inp = new Scanner(fis,"UTF-8").useDelimiter("\\A").next(); 
    return inp; 
    } 
    public void insertUndergraduate(){ 
     AndroidOpenDbHelper androidOpenDbHelperObj = new AndroidOpenDbHelper(this); 
     SQLiteDatabase sqliteDatabase = androidOpenDbHelperObj.getWritableDatabase(); 
     ContentValues contentValues = new ContentValues(); 
     contentValues.put(AndroidOpenDbHelper.COLUMN_NAME_PAGE,inp); 

    } 

pls me aider .....

+0

Quelles erreurs obtenez-vous? rien? ou? – BerggreenDK

+0

il ne montrera pas la page html –

+0

donc la page est "vide"? – BerggreenDK

Répondre

0

Avez-vous essayé cet exemple:

http://mobile.tutsplus.com/tutorials/android/android-sdk-embed-a-webview-with-the-webkit-engine/

Cela ressemble à droite:

WebView engine = (WebView) findViewById(R.id.web_engine); 

String data = "<html>" + 
      "<body><h1>Yay, Mobiletuts+!</h1></body>" + 
      "</html>"; 

engine.loadData(data, "text/html", "UTF-8"); 

Maintenant, si cela fonctionne, je voudrais juste SELECT le code HTML dans la chaîne d'un champ de texte normal dans la base de données.

S'il vous plaît laissez-moi savoir si cela fonctionne et est la réponse.

Questions connexes