Android How to select text from TextView for a book reader? - android

I would like to create a book reader and for this i have a problem of selecting some text and i don't know what is the best way. I read some posts in which they where using EditText for selection. But this is not so usefull because when you long tap it shows select word/select all and the keyboard appears, what i want is only the possibility to select text, listen the selection and then using Spannable/Linkify to edit that portion of text.
If there is no easy thing to use the standard text cursor controllers, can i create a custom cursor controllers or something like that ?
I read this posts:
Select text from TextView?
How to allow the user to select a text range in a TextView (Similar to EditText)
Thank you in advance.
Update:
I found this class android.text.Selection that seems to use the cursor controllers But i don't find any examples on google about it.

Use android:textIsSelectable="true" on your TextView.

I'm made a custom TextView with selection capability by studying Android's source code.
Please see my answer from the other question Android- How can I show text selection on textview?

Related

Make a word in TextVew clickable

I am developing a dictionary app. When I search some keyword it will display its description. Now I want if any keyword (of my database) is used in describing other keyword I want that describing keyword to be clickable (and coloured or/and underlined). So that if I click on that word search will be made using the clicked keyword and will display the result. I am using SQLitedatabase to create database. Please see the attached picture.
Sample picture:
You can use spans to style your text shown on a textview. There is a span subclass called ClickableSpan, which will be able to serve your needs. Takea a look at ClickableSpan also there is another span class called UnderlineSpan which can be used for putting underline for the specified character range. Hope this helps

Custom rendering for text with special syntax

I have a text gathered from API and it consists of custom syntax. I display it using TextView but I need to render special part of the text and convert those text into elements. An example of a text is below.
Oh, that's great idea! Check (user: someuser)'s answer for this.
You can as well look at (ref: a forum post title) or:
(ref: another forum post)
This is a hint for you! (hint: should be displayed as a mini icon
but when clicked, a tooltip should be opened)
Here is a spoiler for you.
---- spoiler ----
some spoiler. this text should not be displayed directly but it should be
converted to a button element. When the button is clicked, this text should
be shown
---- spoiler ----
So, I need to convert (user: someuser) into a link in the view which will be shown as "someuser" but when clicked, it will open a new intent. For (ref: topic) keyword, it's the same. When I hit spoiler, I want to make it a nice button indicating that it's a spoiler and when user clicks, it will expand.
How can I parse this text and show correctly in a view? I don't have problem with parsing but my problem is displaying those elements in the view.
Methods I Tried
I tried WebView instead of TextView thinking that I can convert those into HTML/Js but the performance was terrible. Although I use RecycleView and ViewHolder, WebView is simply an overkill. I need to use some kind of a TextView but with the elements I would like to have.
I also looked at custom HTML tag handling with TextView (thinking I can convert those legacy tags into html) but I failed to see how I can insert button for spoiler tag or insert custom elements like tooltip for hint.
Thank you!

What is the difference between text field types

I am new to android. I was stuck on a problem but I finally solved it.
I was using a TextField instead of CompleteTextViewField so whats the difference between these two and when should I use each one of them?
Thanks
Neither of those classes you mention (TextField, CompleteTextViewField) exist. Do you mean EditText and AutoCompleteTextView? I think the documentation explains it pretty well:
[AutoCompleteTextView is] An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.
That is, use it rather than a normal EditText if you have a set of common autocompletions for what gets entered in the box. The docs also link to a full sample that shows how to populate that list of suggestions with an Adapter.

Android Softkeyboard predictive text

I am trying to get the list of all predictive words based on user input I am using android Softkeyboard sample any idea how should I move on
Regards
Saurabh
Store all the words in a SQLite databse.Thenfor each keypress look for word in database starting with composing text through cursor using like statement and store them in a list. Show this list to the candidate view and you are done :)

Custom dictionary for EditText

Is it possible to create a custom dictionary for an edittext? In other words, can I create a custom list and have the edittext only suggest names from that list? I don't need it popping up useless word suggestions when the user is inputting specific names of people.
Please refer to this link.
https://developer.android.com/resources/samples/SearchableDictionary/index.html
They would have implemented content provider to provide a custom input to the quicksearch. You can try taking a similar approach where in you can make a query and update the result when a user enters each alphabet in your EditText box.
Use AutoCompleteTextView and provide your dictionary in the adapter.
http://developer.android.com/guide/topics/ui/controls/text.html

Categories

Resources