How to use a description with Android TextView for Accessibility - android

I am wondering why Android doesn't support this.
To explain my problem. I am working on an accessibility feature for an Android app.
I have a TextView that displays a number value like 123456.
If I use TalkBack, it will always read just this number value.
What I want it to give this value a context so that TalkBack would read something like: "Number value 123456" I am not able to do that as contentDescription just overrides the text value and hint attribute is read after the value like: "123456 Number value".
Is there an alternative for this? Let me also say that the app is not using a separate TextView which would say "Number value" that TalkBack could read.

The solution I did was to use
var number = 123456
textView.contentDescription = "Number value ${number}"

Related

how to handle TextView set text of "\\uxxxx" failed in android?

I've got a TextView in my app to put my data obtained from scraping.
the data is some chinese words (unicode), the view shows the unicode instead of these chinese words.
I've find out the problem is caused by "\uxxxx" and "\uxxxx". The system return the value of "\uxxxx".
The chinese words can be show if I hard code the string pass into it, for example
Title.setText("\u4F60\u597D\u55CE");
\\ the chinese words can show properly as "你好嗎"
Title.setText("\\u4F60\\u597D\\u55CE");
\\ the words show as "\u4F60\u597D\u55CE"
I try to compare the different:
Log.i("setTitle", String.valueOf(Title.equals("\u4F60\u597D\u55CE")));
//returned false but should be true
Log.i("setTitle", String.valueOf(Title.equals("\\u4F60\\u597D\\u55CE")));
//returned true but should be false
I've tried
Title.replace("\\\\u","\\u");
Title.replace("\\\\","\\");
these all provides the same result in my comparison code
I've even tried
Title.replace("\\","").replace("u", "\\u")
I still cannot get the result I want.
Just want to ask is there any way I can show chinese character with unicode in TextView.setText()?
Just replace all \\u with \u before setting it to the Textview and that should work.

Input type = Registration number

How do I set the input type for registration number. For example my university has specific format for registration number i.e. CIIT/SP17-mcs-044/Atk. I want CIIT/ATK is written already and Sp17-mcs-044 as a hint.
You can't define a random types of input type. You can only have one of these types as inputType.
If you want any custom behaviour, you might use TextWatcher and validate it
As #Tim has stated, the input type would be text over here and when user types in that EditText then check if the input is correct by using RegEx, and then show any message when the input is correct, for that you will need to add an OnTextChangedListener, about which you can learn more on official documentation.
Now, CIIT/ATK can be a TextView placed right before the EditText so it will be written already and will be uneditable. And yes, add that in final string after getting the input, like this:
finalInput = "CIIT/ATK" + input;

How to test the android app language changed or not?

In my android app, I have 3 options for language selection.i.e; Hindi,English,French
Programmatically changed default language(English) to Hindi.
How to verify whether app language changed to Hindi or not.(programmatically)
please help
To check whether language changed or not there may be many ways to verify but simply you can assert page title or that drop down text with expected text.
When the language is changed, take the reference of any text or tile or any element placeholder or label, and verify the string by using equalsIgnoreCase("") method.

To Parse or not to parse the content of the EditText field if the textInput attribute set to "Time"

I don't know if I should parse the content of the EditText field called "startTime" if the textInput attribute is set to "Time."
The input keyboard offers the "Phone Number" set of keys which doesn't quite work for entering time (i.e. I wasn't able to add a period [is present in the keyboard] or a semicolon [is missing] as in 10.55 or 10:55)
Plus, I want to know what format (12-hour vs. 24-hour) is used by default.
It's important because then the question of handeling am/pm distinction comes into the picture.
Please include how to "set/fix it" snippets of code with your answer.

How to search and Highlight Text within an EditText

I've searched high and low for something that seems to be a simple task. Forgive me, I am coming to Android from other programming languages and am new to this platform and Java.
What I want to do is create a dialog pop-up where a user enters text to search for and the code would take that text and search for it within all the text in an EditText control and if it's found, highlight it.
I've done this before, for example in VB and it went something similar to this pseudo code:
grab the text from the (EditText) assign it to a string
search the length of that string (character by character) for the substring, if it's found return the position (index) of the substring within the string.
if found, start the (EditText).setSelection highlight beginning on the returned position for the length of
Does this make sense?
I just want to search a EditText for and when found, scroll to it and it'll be highlighted. Maybe there's something in Android/Java equivalent to what I need here?
Any help / pointers would be greatly appreciated
grab the text from the (EditText) assign it to a string
Try the code sample below:
EditText inputUsername = (EditText) findViewById(R.id.manageAccountInputUsername);
inputUsername.getText().toString()
^^ Replace the IDs with the IDs you are using.
After this, you have the standard string methods available. You could also use Regex for a complex search query:
http://developer.android.com/reference/java/lang/String.html
http://developer.android.com/reference/java/util/regex/package-summary.html

Categories

Resources