Reputation: 1165
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/.....
Upvotes: 0
Views: 134
Reputation: 75645
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.
Upvotes: 1