从数据库中显示html页面

时间:2013-03-30 01:55:46

标签: java android sqlite

我将html字符串插入数据库。然后我在webview中加载该字符串 仅显示null。请帮我。这是我的代码:

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);


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



    }
    public void insertUndergraduate(){
        AndroidOpenDbHelper androidOpenDbHelperObj = new AndroidOpenDbHelper(this);
        SQLiteDatabase sqliteDatabase = androidOpenDbHelperObj.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        inp = "<html>"+"<body><h1>hai mohan</h1></body>"+"</html>";
        contentValues.put(AndroidOpenDbHelper.COLUMN_NAME_PAGE,inp);

    }
}

1 个答案:

答案 0 :(得分:0)

您未在inp

之前设置browser.loadData(inp, "text/html", "UTF-8");