1

I am creating an android app that uses the MathQuill library. The application consists of a WebView that uses the MathQuill equation parser and a keybord (implemented via activity_main.xml and MainActivity.java) which has buttons that write math symbols to a WebView.

I need to create a backspace button functionality which I don't know how to do.

Backspace button in layout file:

<Button
    android:id="@+id/button_backspace"
    android:layout_width="35dp"
    android:layout_height="35dp"
    android:text="b"
    android:background="@drawable/button"
    android:padding="0dp"
    android:textSize="15sp"
    android:layout_margin="1dp"
/>

WebView in layout file:

<WebView
    android:id="@+id/web_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="blocksDescendants"
    android:focusable="false"
    android:focusableInTouchMode="false"
/>

WebView init in MainActivity.java

et = (WebView) findViewById(R.id.web_view);
et.getSettings().setJavaScriptEnabled(true);
et.loadUrl("file:///android_asset/some.html");

Backspace button in MainActivity.java:

Button btn_backspace = (Button) findViewById(R.id.button_backspace);
btn_backspace.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        et.loadUrl("javascript:input(\"\\b\")");
    }
});

Android asset html fragment:

var MQ = MathQuill.getInterface(2); 
var mathField = MQ.MathField(mathFieldSpan, {
  spaceBehavesLikeTab: true,
  handlers: {
    edit: function() {
      mathField.focus()
      //latexSpan.textContent = mathField.textContent
      latexSpan.textContent = mathField.latex();
      Android.getImageUrl(mathField.latex())
    }
  }
});

function input(str) {
    if(str == "tangens"){
        str = "\\tan"
    }
    mathField.cmd(str)
    mathField.focus()
}

the input function is used to write math symbols to a WebView.

I tried sending a \b char with no success.

New contributor
Andy is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
7
  • What are you doing for other input? Commented Oct 20 at 11:54
  • @tomerpacific I am displaying formulas in webview, for example for "\sin" input "sin" is displayed in webview (et.loadUrl("javascript:input(\"\\sin\")");) Commented Oct 20 at 12:04
  • @tomerpacific Other inputs consist of aritmethic operations (+, -, *, /, ...), digits (0, 1, 2, ..., 9) and functions (sin, cos, tan, ctg), and constants Commented Oct 20 at 12:19
  • Have you tried "\b"? \b is the backspace character Commented Oct 20 at 15:48
  • 1
    Alternatively, there is mathField.keystroke('Backspace') which you could then add a function such as javascript:doBackspace() which performs same and called by button handler. Commented Oct 20 at 18:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.