I'm new to android coding practice
ABB20180001
Suppose this as my first id, and i wish to auto-increment this by 1 using shared preferences and use as employee id.
like ABB20180002, ABB20180003, ABB20180004 etc.
I'm new to android coding practice
ABB20180001
Suppose this as my first id, and i wish to auto-increment this by 1 using shared preferences and use as employee id.
like ABB20180002, ABB20180003, ABB20180004 etc.
You can use a specific
radix
to parse the number into a long, increment it, and then convert it back to String.If you're using all letters, then you can use
36
as the radix:It's possible that your number is just a hexadecimal number. In that case, you can use
16
as the radix instead of36
as shown above.Note that if
ABB
is just a prefix, then the above won't work (incrementing by 20 will returnABB2018000L
).If
"ABB"
is just a static prefix, then you can useAnd finally, if
"ABB"
can change, you can use a regex like this (the example below assumes that prefix is of length 3, change accordingly):You can't increment alphanumeric values directly. if want to do so you need to write some lines of code for it
here is activity_main.xml
here is MainActivity.java
hope this will help you.