Is there any good simple way to format fields as I want.
I'd like to separate field value from field text. For example, I'd like to group number by 4, so when I set field's value to 123456789 it would show as 1 2345 6789, but when I get value I'll get number without spaces (123456789).
I think, this is the way widgets works on other tools, i.e. .Net VS. I can set there some mapping, formats and so on, so what is shown depends on value and format/mapping.
In android this must be done for passwords fields. It has text as value, but it shows some dots (value is mypassword and field shows **********).
I guess you just want to display the number in nice format, please use the APIs provided by PhoneNumberUtils.
static String formatNumber(String source)
static void formatNumber(Editable text, int defaultFormattingType)
You could set the formatted string to the text view for displaying nicely. But the saved content is still the raw content without any format.
Please refer to the SDK document at http://developer.android.com/reference/android/telephony/PhoneNumberUtils.html
Related
I'm using com.tom_roush:pdfbox-android:1.8.10.1 version of PDFBox.
I have the following code.
val skillList = listOf<String>("Athletics","Acrobatics","Sleight of Hand", "Stealth","Acrana", "History","Investigation","Nature", "Religion", "Animal Handling", "Insight", "Medicine", "Perception", "Survival", "Deception", "Intimidation", "Performance", "Persuasion"
private fun getField(acroForm:PDAcroForm,name:String): PDTextField {
return acroForm.getField(name) as PDTextField
}
var temp = 0
skillList.forEach {
val field = getField(acroForm,it.name)
temp += 1
field.value = temp.toString()
}
Here is a link to the PDF.
PDF in question
My problem is that my final PDF (all fields with unique names that match the above list), has many of them being set with the 17th out of 18 passes. What am I doing wrong?
This is a bug in PDFBox (1.8.x and 2.x) when filling PDF forms which only occurs if in the original form multiple fields share the same XObject as appearance stream.
In detail
Your original document contains many empty text fields. Several subsets of them share the same appearance stream, e.g. "Athletics" and "Religion":
As you can see they both share the XObject in PDF object 479.
When PDFBox fills in the form values, it first sets the value of "Athletics" to "1" and also updates the appearance XObject to show "1", and later it sets the value of "Religion" to "9" and updates the appearance XObject to show "9". The end result: In a viewer both "Athletics" and "Religion" show "9" as value.
The issue is that PDFBox assumes it can simply update an existing appearance stream when setting the value of a form field. Actually it must replace it, probably also the AP dictionary if it happens to be indirect as it might also be shared.
A work-around
A work-around in your case is to drop the existing empty appearances before setting the field:
field.getDictionary().removeItem(COSName.AP)
field.value = temp.toString()
(Probably that line can be shortened in Kotlin to field.dictionary.removeItem(COSName.AP) but I know next to nothing about Kotlin...)
Backgrounds
One might wonder whether a construction as found in the source PDF here (i.e. appearance streams shared by multiple text fields) is valid at all. But indeed I could not find anything forbidding this in the PDF specification, on the contrary the following section about annotations in general (form field widgets are special annotations) can be taken to explicitly allow it:
A given annotation dictionary shall be referenced from the Annots array of only one page. This requirement applies only to the annotation dictionary itself, not to subsidiary objects, which may be shared among multiple annotations.
(both ISO 32000-1 and ISO 32000-2, section 12.5.2 "Annotation Dictionaries")
I'm developing Android app which uses this method:
public static String currencyFormat(BigDecimal n) {
return NumberFormat.getCurrencyInstance().format(n);
}
which formats number based on Locale currency.
How to revert back from currency format, e.g. $35, to 35? Note that I cannot just remove First character because different locales have different currency name lengths.
You must store the currency unit in a separate field, encapsulated into some higher-order abstraction such as a final value class (with appropriate equals and hashcode defined), eg called CurrencyAmount. [if you do scala, basically you want a case class]. Any other solution will require you to 'reverse engineer' the unit portion from the amount portion and depending on the complexity of your spec of allowable values, it might be reliable only to various degrees. I would just encode the two portions in their own fields and solve this for all cases.
You might try to cut out all non numeric characters from a String with a regex.
Try this.
I wanna take an hour as input from user using a Number Picker, but it doesn't show the + and - buttons, it's just a values wheel
There are different ways that you can do this. I would take that string and then parse it down to see what you find then handle the string accordingly. Say you have an edit text field and it returns the string HourText. The way I would handle this, would be to use a number picker, set an upper and lower limit. Then you are returned a type int. From that you can use >=20 or >=50. In my mind using a numberPicker, and then handling the value accordingly sounds easier.
I am working on a project in which i am getting value from excel sheet(in assets android) and reflecting data in list view.
problem is:: phone no is not in proper format.
9.777123455E9 instead of 9777123455
When it's a phone number, you should always store the cell data as text, even if it consists only of digits, since a phone number is no mathematical number and when doing operations on it, you want to treat it as a string of characters (i.e. text).
If you input a phone number that looks to Excel like a mathematical number, it will interpret it as a number and in consequence will do things to it that make sense for numbers, but not necessarily for phone numbers, such as displaying it in scientific format.
To force Excel to treat your number as text, precede it with a single quote (apostrophe) when entering it. That is, enter into the cell:
'9777123455
It will be displayed without the single quote, just as you expect a phone number to be displayed and can be processed as text.
double d=9.777123455E9;
NumberFormat formatter = new DecimalFormat("#");
System.out.println(d);
System.out.println(formatter.format(d));
output
9.777123455E9
9777123455
E9 simply means multiply by 10^9
Update:
As #blubberdiblub mentioned, for phone numbers, it makes sense to change it to text. But for other cases, If you need to do mathematical operations leaving it in the scientific format works. You can right click on the column name and select formatting option to set the type of data the column will handle (number , text etc). If you want don't want to change the phone number to text and still see the number, simply increase the width of the column. The number will be shown full (without the "E").
I am writing a dictionary-type app. I have a list of hash-mapped terms and definitions. The basic premise is that there is a list of words that you tap on to see the definitions.
I have this functionality up and running - I am now trying to put dynamic links between the definitions.
Example: say the user taps on an item in the list, "dog". The definition might pop up, saying "A small furry [animal], commonly kept as a pet. See also [cat].". The intention is that the user can click on the word [animal] or [cat] and go to the appropriate definition. I've already gone to the trouble of making sure that any links in definitions are bounded by square brackets, so it's just a case of scanning the pop-up string for text [surrounded by brackets] and providing a link to that definition.
Note that definitions can contain multiple links, whilst some don't contain any links.
I have access to the string before it is displayed, so I guess the best way to do this is to do the scanning and ready the links before the dialog box is displayed.
The question is, how would I go about scanning for text surrounded by square brackets, and returning the text contained within those brackets?
Ideally the actual dialog box that is displayed would be devoid of the square brackets, and I need to also figure out a way of putting hyperlinks into a dialog box's text, but I'll cross that bridge when I come to it.
I'm new to Java - I've come from MATLAB and am just about staying afloat, but this is a less common task than I've had to deal with so far!
You could probably do this with a regular expression; something like this:
([^[]*)(\[[^]]+\])
which describes two "match groups"; the first of which means any string of zero or more characters that aren't "[" and the second of which means any string starting with "[", containing one or more characters that aren't "]", and ending with "]".
Then you could scan through your input for matches to this pattern. The first match group is passed through unchanged, and the second match group gets converted to a link. When the pattern stops matching your input, take whatever's left over and transmit that unchanged as well.
You'll have to experiment a little; regular expressions typically take some debugging. If your link text can only contain alphanumerics and spaces, your pattern would look more like this:
([^[]*)(\[[\s\w]+\])
Also, you may find that regular expression matching under Android is too slow to be practical, in which case you'll have to use wasyl's suggestion.
Quite simple, I think... As the text is in brackets, you need to scan every letter. So the basic recipe would be :
in a while loop scan every character (let's say, while i < len(text))
If scanned character is [:
i++;
Add letter at index i to some temporary variable
while (character # i) != ']' append it to the temporary variable
store this temporary variable in a list of results.
Some tips:
If you use solution above, use StringBuilder to append text (as regular string is immutable)
You might also want (and it's better, I think) to store starting and ending positions of all square brackets first, and then use string.substring() on each pair to get the text inside. This way you'd first iterate definition to find brackets (maybe catch unmatched ones, for early error handling), then iterate pairs of indices...
As for links, maybe this will be of use: How can I get clickable hyperlinks in AlertDialog from a string resource?