Answer the question
In order to leave comments, you need to log in
How to use rich text with tables in TextView?
In the SQlite database, I plan to store the formatted text in html format. Further, this text will be displayed in the TextView. Hence the question - what html tags "understand" textView and, accordingly, how to display these tags on the page. As far as I know, Html.fromHtml is already deprecated
https://stackoverflow.com/questions/37904739/html-...
Moreover, it does not support table td tr tbody table tags, etc.
Is there an alternative to what format to store data in in the database and how to display them. In a DB there can be a text with the table for example.
String Resources also doesn't support table tags - daniel-codes.blogspot.com/2011/04/html-in-textview...
Original source: https://stackoverflow.com/questions/9754076/which-...
PS the option of using Webview instead of Textview is hardly suitable for recyclerView...
Answer the question
In order to leave comments, you need to log in
I would like to hear other opinions on this issue, but I solved this issue as follows:
1) connected the library - https://github.com/PrivacyApps/html-textview
2) if there are table tags in the database <table></table>
, then instead of the table a link is displayed when clicking on which opens the WebView. Accordingly, with the help of putExtra I transfer the table and receive it in WebView.
Below is the code I used:
1) build.gradle --> compile 'org.sufficientlysecure:html-textview:3.5'
2) Since I'm building the activity through recyclerview, I've added the following code to the adapter.
I add an inner class:
class ClickableTableSpanImpl extends ClickableTableSpan {
@Override
public ClickableTableSpan newInstance() {
return new ClickableTableSpanImpl();
}
@Override
public void onClick(View widget) {
Intent tableIntent = new Intent(mContext, WebViewActivity.class);
tableIntent.putExtra("extra_table", getTableHtml());
mContext.startActivity(tableIntent);
}
}
descriptionViewHolder.htmlTextViewText.setClickableTableSpan(new ClickableTableSpanImpl());
DrawTableLinkSpan drawTableLinkSpan = new DrawTableLinkSpan();
drawTableLinkSpan.setTableLinkText("-- Просмотреть таблицу --");
descriptionViewHolder.htmlTextViewText.setDrawTableLinkSpan(drawTableLinkSpan);
descriptionViewHolder.htmlTextViewText.setHtml(descriptionList.get(position).getText());
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Получаем таблицу
String webViewTable = getIntent().getStringExtra("extra_table");
webView = (WebView) findViewById(R.id.webViewTable);
webView.loadData(webViewTable,"text/html; charset=UTF-8", null);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question