code not get input expression from textbox in webview

Put your problem here if it does not fit any of the other categories.

code not get input expression from textbox in webview

Postby Sana malik » Fri May 03, 2013 2:45 pm

package com.example.hi;



import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity
{
private boolean _hasAnsweredQuestion =false;
/** Called when the activity is first created. */
@SuppressLint("SetJavaScriptEnabled") @Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView webView=(WebView)findViewById(R.id.webview1);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient()
{
@Override
public void onPageFinished(final WebView view,final String url)
{
super.onPageFinished(view,url);
if(_hasAnsweredQuestion)
return;
_hasAnsweredQuestion=true;
// final String mathProblem="2+1";
// String mathProblem;
EditText editText1 = (EditText)findViewById(R.id.editText1);
String mathProblem=editText1.getText().toString();
final String newUrl="javascript:AndroidFunction.showToast("+mathProblem+");";
webView.loadUrl(newUrl);
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new Object()
{ @SuppressWarnings("unused")
@JavascriptInterface
public void showToast(final String webMessage)
{
Toast.makeText(MainActivity.this,webMessage,Toast.LENGTH_SHORT).show();
}
},"AndroidFunction");
webView.loadUrl(" ");
}}
Sana malik
Freshman
Freshman
 
Posts: 2
Joined: Fri May 03, 2013 2:36 pm

Top

Re: code not get input expression from textbox in webview

Postby Sana malik » Fri May 03, 2013 2:51 pm

onPageFinished function is invoked and end execution before i write some mathematical expression in the textbox. and hence nothing is written on toast.. this is problem in this code.. i want to edit this code so that it get input expression on runtime from user than execute the function so that result display on toast... This code works fine when i hard code expression and store it in string (final String mathProblem="2+1";) but not work for runtime expression i write in the textbox.. plz help me
Sana malik
Freshman
Freshman
 
Posts: 2
Joined: Fri May 03, 2013 2:36 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 17 guests