我正在研究一个从firebase获得价值并推入webview html的项目。但是我一步一步地前进。而且我还没有连接firebase。因为首先我需要将动态字符串传递到html。我可以在class和html之间传递字符串值。但是问题是如何传递动态变化的字符串?
public class smdene extends AppCompatActivity {
WebView wvContent;
String soma = "sas";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.smdene);
WebView wvContent = (WebView) findViewById(R.id.wv_html_content);
WebSettings webSettings = wvContent.getSettings();
webSettings.setJavaScriptEnabled(true);
wvContent.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished (WebView view, String url) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
// view.evaluateJavascript("loadMsg('How are you today!')'"+soma+"'", null);
view.loadUrl("javascript:loadMsg('How are you today!'+'"+soma+"')", null);
} else {
//view.loadUrl("javascript:loadMsg('How are you today!')'"+soma+"'");
view.loadUrl("javascript:loadMsg('How are you today!'+'"+soma+"')");
}
}
});
wvContent.loadUrl("file:///android_asset/lola.html");
/**I tried to change value with click**/
findViewById(R.id.dokan).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//createUser();
soma = "simo";
}
});
}
}