Generating fast JSON by EditableText Fields - android

I would like to create something similar to Inputs of HTML form. Each input has a name and value attribute which is nicely playing together.
However so far I have just found android:tag which might be utilized as name attribute of inputs.
<EditText android:id="#+id/passwordEdit"
android:tag="name"
android:inputType="textPassword"/>
Simply what I would like to create is building a JSON Object by only EditText's as this:
jsonObject.put(editableField.getXXX, editableField.getText())
Please note that the point is here just using layout files in order to build a JSON Object.
Are there any convention for such kind of usage or another appropriate attribute for storing dummy values?
Thanks

Related

eg: I would want to write an xpath that would click an element based on the input value

Below is the element for which I am trying to write an XPath
<div class="displayInlineBlock Roman30Px_New bsbAccountFont ng-binding">123456</div>
The above element is many on the page and one can distinguish using the value which is at the end i.e. 123456.
XPath I tried was this way and on trying I found that there was an innerText that holds the value 123456.
//*[#class='displayInlineBlock Roman30Px_New bsbAccountFont ng-binding']
I am not sure how to make this element get clicked for each specific value I enter.
Few other ways i tried was
xpath=from_frst_part=//div[innerText='123456'']/innerText
but nothing worked.
Another way I was thinking is finding the number of elements on the page and get attribute but I felt it was long and cumbersome.
i think a suitable xpath could also be as so, by using the and keyword instead of separating the attributes to individual brackets:
//div[#class='displayInlineBlock Roman30Px_New bsbAccountFont ng-binding' and text()='123456']

multiple markers error for android:hint

I'm trying to learn android, I'm having trouble with user input
I've used editText to get users to enter a date and email which is all fine, then i add a hint
for these fields like so:
android:hint="#+string/DD/MM/YY"
android:hint="#+string/example#example.co.uk"
and i get multiple marker errors in the generated files :/
I don't think you can use special characters in string names. Give it a meaningful name like support_email. You can find more information here.

Parsing double quotes from xml

I have xml file in server. I am parsing this xml using DOM(xml is not big). In one node there is string with double quotes.
<NODE1>hello "world"</NODE1>
When i see this xml url in browser and check its source it looks like this:
<NODE1>hello "world"</NODE1>
So when i parse this value i get string till double quotes. It seems after double quotes parser doesn't go forward. Any help ? I want to use DOM only in my current situation. This xml is used by other platform also apart from android. Like in iPhone its working perfectly. What should I do to read all value in android using DOM.
Thanks.
I'm not sure if I understand your question, but have a look at using CDATA
http://www.globalguideline.com/xml/XML_CDATA.php
A xml that contains double quote in a value is not valid according to specification: http://www.devx.com/tips/Tip/14068. I would suggest that you escape the special characters server side otherwise you will not be able to parse the xml.

Show a bulleted list from Strings.xml file in android

I have a problem that I want to show a bulleted list contents which is resided in strings.xml file as an array elements. Then the problem is that how to convert the array elements in Html List format? Can any one suggest any solution regarding the same.
Thanks in advance
I just put the symbol directly into the strings.xml without any codes or anything:
<string name="msg_sms_no_note">• Notes and attachments will not be sent.</string>
There's a problem with the approach suggested by some of the answers in this thread of prepending the bullet unicode character (i.e. \u2022) to each of the Strings in the String array: You don't get proper indentation when one or more Strings in the String array span multiple lines. What you get is formatting as follows:
In order to get proper indentation, you're better using BulletSpan. In doing so, you'll get formatting as follows:
To use BulletSpan, you need to create a SpannableStringBuilder instance and append each String in your String array to this SpannableStringBuilder instance. As you append each String, call the setSpan(what:start:end:flags:) method on the SpannableStringBuilder instance passing in a BulletSpan instance for the what parameter. You can find an example of this in the appendBulletSpan(...) Kotlin extension function located here.
I think, the most elegant way of doing this is to load a WebView and put your string in it. this way, you use the common ul/li convention and you can style it at your leisure with CSS.
Use the unicode escape sequence "\u2022" in strings.xml
like so:
<string name="menu_new_trip_desc">View them in: \n\u2022 Table

XML within an Android string resource?

I was wondering if I could place XML within /res/values/strings.xml? I ask this because I am checking for the XML data file for my application, if it does not exist yet then it creates it from the default contents that will be contained as a string resource.
Eclipse tries to change the less than and greater than tags to their corresponding HTML entities when using the GUI to edit the strings. Is eclipse on the right track? Because I should think that it will be written out into my file as HTML entities too. Could I use getText() rather than getString() to convert the entities back into tags?
Yes you can, just use CDATA
<string name="stringName1"><![CDATA[<html>bla</html>]]></string>
It will obviously not work unless you escape characters in there such as < or > or &.
If you do encode the XML, it should work fine but probably not the best way to do it. I would prefer binary resource.
For putting in string.xml, you may encode using
String encoded = URLEncoder.encode(xml);
And decoding is the opposite.
For binary, you place it in RAW folder and you get a binary stream and turn it to string and load.
I have done this way:
Put your string in strings.xml
<string name="my_string"><![CDATA[Your long text here]]></string>
How to use:
<TextView
android:id="#+id/textView"
android:text="#string/my_string"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Done

Categories

Resources