0

I use the MathJax-library to format strings into nice mathematic formulas in my financial app. It works good but I am not happy with the code by now. What i do is to get an instance of every mathjaxview and then use a customized setText-function in the library, simply in source code:

     final MathJaxView mathJaxViewStockCall = findViewById(R.id.mathjax_stock_callview_id);
    final MathJaxView mathJaxViewStockPut = findViewById(R.id.mathjax_stock_putview_id);
    final MathJaxView mathJaxViewD1Stock = findViewById(R.id.mathjax_stock_d1_view_id);
    final MathJaxView mathJaxViewD2Stock = findViewById(R.id.mathjax_stock_d2_view_id); 


        String call_stock = "$\\ c = SN(d_1)  -Xe^{-r(T-t)} N(d_2)$";
    String put_stock = "$\\ p = Xe^{-r(T-t)} N(-d_2) - SN(-d_1)$";
    mathJaxViewStockCall.setText(call_stock);
    mathJaxViewStockPut.setText(put_stock);

    //d1, d1 aktie
    String d1_stock = "$ d_1 = \\frac{ln(S/X) + (r + \\sigma^2/2)(T - t)}{\\sigma \\sqrt {T-t}}$";
    String d2_stock = "$ d_2 = \\frac{ln(S/X) + (r - \\sigma^2/2)(T - t)}{\\sigma \\sqrt {T-t}}$";
    String d2_abbrev_stock = "$ = d_1 - \\sigma \\sqrt {T-t}$";
    mathJaxViewD1Stock.setText(d1_stock);
    mathJaxViewD2Stock.setText(d2_stock);
    mathJaxViewD2AbbrevStock.setText(d2_abbrev_stock);

What I would like to do is to use the customized (overidden) setText-method in xml-file such as:

    <io.github.sidvenu.mathjaxview.MathJaxView
            android:id="@+id/mathjax_stock_callview_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            .... use the customized settext here
            />

Because then i could put all mathjax raw formulas in values/string-folder and get the string from there via

@string/.....

1 Answer 1

1

You can use Android's Data Binding library and then create your own Binding Adapter implementation of setText() for android:text attribute (or you can come with own attribute instead - this actually does not really matter much unless you got special use case in your app). Then you put all the code in said adapter and you are done. That way you will no longer need to explicitly execute the code to populate your widgets all is being handled "in background" via data binding generated code.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks will look into this - by the way, may it improve performance by using data binding library ?
No, this is not what data binding is for.

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.