I'll try to keep it simple, but it's two part.
In my Android app, I have a textview anf 4 buttons (question and 4 answers). I'm attempting to utilize the html <sub>subscript</sub> and <sup>superscript</sup>. It's working on the textivew (ie. the text is formatted the way I want it to be), but when I try to do the same thing on the buttons in the exact same way, it doesn't format them. X2 just becomes "X2" without superscript.
Why is this the case and how can I get it to work on the buttons like it works on the textview?
If it helps, I noticed something. If I pull the same string to the textview and to the buttons (keep in mind I'm pulling the strings from a variable set in a java structure I made... questions/answers I coded into arrays), the textview will read "Question # 1" and the button will read "QUESTION # 1". So, somehow the button is formatting the text and I wasn't aware of that. Could this be the reason the <sub> html code isn't working on the buttons? What's causing this and how can I fix it?
Thank you.
Related
I want to convert text which is in a EditText to chips
There are a lot of libraries for and related question to it like this , this and this question. All of them are hard to understand (at least for me ), because all of those library have features I am not interested in.
I want to convert a text to chips which is entered into an EditText (programmatically). Is there a straight forward way to do it?
P.s. by saying Straight Forward i meant i dont want this auto completion , suggestions and the text that am entering is entered programmatically not manually
Please read before labelling this as a duplicate.
I am creating an application that calculates how fast a person can type by calculating WPM and CPM. However I have hit a snag with the UI as I found out that you cannot really highlight individual strings in a TextArea. My goal is to compare what the user is typing to the random text that is generated by having it so that the text is being dynamically coloured or highlighted as the user is typing.
See http://10fastfingers.com/typing-test/english to get an idea of what I mean
I recently read the following post Highlighting Strings in JavaFX TextArea
I was trying to achieve the same goal of highlighting individual strings inside a javaFX TextArea until I realised that it pretty much is not possible. So I looked into TextFlow which does allow me to edit individual strings. The problem with TextFlow is that all 200 of the generated words would have to appear at once which is not what I want. With a TextArea not all the text has to be displayed at once.
This is what I have so far just so that you can further get an idea of where I am heading with this.
I'm working on an Android app, and I need to be able to include the exponents/powers into a string (Java). I've done some searching and it seems that my scenario is making it difficult. I've looked into options such as ALT+ codes and Unicode. I'm not entirely sure if either of those, or any other options, are actually possible (I know the ALT+ codes only have '1' '2' and '3' subscripts oddly enough).
So, what's my best option, if any?
I'd like to keep it as simple as possible. I have a lot of strings to write (like math problems) and the need to subscript/superscript numbers is random. Can this be done easily?
EDIT: I suppose I was vague. My app is for studying. And the questions/answers are put into arrays and randomized each time. I'd like to be able to set the strings in the Java file as they are now
question[0].text = "solve x^2 if x=5";
But instead of the user seeing "^2", I'd like to use the actual superscripts.
ANOTHER EDIT:
global.java (class/structure that holds questions/answers)
question[0].question = "Question Text. I would like to add a superscript or two here, as if it were a math problem";
question[0].answer[0]. = "Answer 1. Add a subscript here";
question[0].answer[1]. = "Answer 2. Add another superscript here.";
question[0].answer[2]. = "Answer 3. Etc.";
question[0].answer[3]. = "Answer 4. Etc.";
Activity XML
<!--QUESTION-->
<TextView
android:id="#+id/textQuestion"/>
<!--ANSWERS-->
<Button
android:id="#+id/answerOne"
android:onClick="checkAnswer"/>
<Button
android:id="#+id/answerTwo"
android:onClick="checkAnswer"/>
<Button
android:id="#+id/answerThree"
android:onClick="checkAnswer"/>
<Button
android:id="#+id/answerFour"
android:onClick="checkAnswer"/>
Activity Java
//SET QUESTION STRING TO TEXTVIEW
textQuestion.setText(questionDatabase.getQuestion(index));
//SET ANSWER STRINGS TO BUTTONS' TEXT
buttonOne.setText(questionDatabase.getAnswer(index, 0));
buttonTwo.setText(questionDatabase.getAnswer(index, 1));
buttonThree.setText(questionDatabase.getAnswer(index, 2));
buttonFour.setText(questionDatabase.getAnswer(index, 3));
"NEXT" and "PREVIOUS" buttons allow the user to move through the questions by incrementing/decrementing the "index".
So, because of this, the activity never knows (I don't think) which questions/answers need text to be superscript, and why I'd like to be able to set the questions/answers sub/superscript myself when I enter the questions/answers into the array. Can this be done?
EDIT: #jared burrows was very helpful in chat and has helped me almost reach the end of my issue. I'm now able to use setText(Html.fromHtml()); on my textview (question text) and it shows the subscript and superscript properly. But on my buttons (answers) I tried to employ the same tactic and it doesn't work the same. "X2" just becomes "X2". Why is this? Why don't my buttons accept the html just like the textview.
Superscript:
textView.setText(Html.fromHtml("X<sup>2</sup>"));
Subscript:
textView.setText(Html.fromHtml("X<sub>2</sub>"));
References:
Subscript and Superscript a String in Android
http://www.w3schools.com/tags/tag_sub.asp
http://www.w3schools.com/tags/tag_sup.asp
The answer to this was a combination of help from #Jared Burrows and AlanV. So thank you to you both.
view.setText(Html.fromHtml(stringGoesHere));
This does work, but out of the box it doesn't work for buttons due to some frustrating feature in (I think) Android 5.0. Buttons are automatically set to all caps, and because of this, it overrides the html formatting.
So, to allow buttons the ability to use html properly, you must set the attribute to false.
<button
android:textAllCaps="false";/>
Thanks again to Jared Burrows and AlanV.
How to make EditText Field uneditable over property inputType when
inputType="textPassword"
My problem is that following code line makes the password visible.
password.setInputType(InputType.TYPE_NULL);
Already tried following, but remains editable
password.setEnabled(false)
If you play with :
edittext.setFocusable();
edittext.setFocusableInTouchMode();
You should be able to make the EditText editable/uneditable when you want.
Using this: How to make EditText not editable through XML in Android?
You said that you wanted your field to be editable after some logic. Do this:
KeyListener keyLis = textView.getKeyListener();
textView.setKeyListener(null);
Then, when you want your TextView to be editable again, do this:
textView.setKeyListener(keyLis);
Documentation for TextView class:
Two methods:
getKeyListener()
setKeyListener(KeyListener keyLis)
EDIT
I didn't find any beautiful answers, but I did find a few alternative ways to do this:
To make uneditable
valueText.setEnabled(false);
valueText.setClickable(false);
valueText.setFocusable(false);
And then,
valueText.setEnabled(true);
valueText.setClickable(true);
valueText.setFocusable(true);
You can also change what happens when the text is edited to make nothing happen: Can we have uneditable text in edittext
There are some other very wild solutions, out there. They're not beautiful at all, though.
I recommend using the initial solution, unless somebody finds a quicker way.
Sorry I couldn't find a better way to do this :(
I'm developing an ebook app for Android. when the text length given in string.xml is very large (around 500 words) it is not shown in the text view.
It took a while for me to figure this out. I have two text views and one is working propoerly as it is a small paragragh with 100 words but the secound TextView is larger and when the event is triggered it shows an empty screen.
Any char limitation in TextView?? wot would be the alternative?? Please help me.
Thanks in advance.
TextView doesn't sound like the correct component for your use. I would imagine you would get much better results using WebView.
You can define your content in HTML files instead of putting that much text into strings.xml.