I'd like to create an EditText that allows user to quickly put in a specific date in format dd/mm/yy, where he only needs to pass day, month and year numbers, without worrying about slashes and overall formating. Is it possible to do that with one EditText or is my only option to create multiple EditTexts and jump the cursor between them?
You could add the date mask "##/##/##" in your EditText. Here is a tutorial on how to do this:
https://medium.com/#diegoy_kuri/masks-in-android-edit-text-fields-33a2fd47f1af
You could solve these by :
Add addTextChangedListener to your editText
Inside afterTextChanged function, add logic to append '/' after user put day and month
By this way, you will get same result for date that displayed to user and date that your code record.
Related
I'm working on an application where need to complete date automatic/suggest while writing. Thing is user can type other text as well so how to sure when he start writing for date.
For reference: I have found similar feature on slack app.
Any suggestion?
Add TextWatcher to the EditText view. In one of it's methods for example beforeTextChanged or onTextChanged get the last entered word (or char sequence - it's up to you to decide which part of entered text you want to check). Apply regular expression to it to check if it looks like date or not. Again it's up to you to decide what looks like date and what is not. If it looks like date - provide users with UI for auto completion or autocomplete by our own. Don't forget to move cursor to the end of autocompleted text using EditText.setSelection() method.
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'm using simplecursoradapter with a sql and a listview, how can I add section title in it? My database has a timestamp, in the simplecursoradapter the value is input to the listview directly, but I want to have the timestamp converted to weekday before putting in the listview, how can I do that?
To add a header you should Use ListView.addHeaderView(View v). To get a date (assuming you are using UNIX time, i.e. System.currentTimeMillis()) you can use something like Date date = new Date(Long.parseLong(timeInMillis))
Is there a way in android app that we can add some text or image and we can change that dynamically without adding new version. Like we have this text: Today's deal is: 1
then in a week if i want that text to show as: Today's deal is: 2.
Is there a way to do this, for an app which does not have a server and is stand alone app.
A text or image can be altered during run time; so how you choose to change that is up to you. You would have a simply switch statement depending on the day of the week for your specific example.
TextView tv = (TextView) findViewById(R.yourxml.name);
tv.setText("Monday!");
...
One way I can think of to achieve this is by writing a long value in the shared preferences for a Date object. Each time you start the application we will check if it's been 1 day since the value was saved. Also maintain the different string you want to display as string array in the resources.
I hope it helps...
I have a question. In my app I have saved in my database some lists. Each list has asociated a date in this format 6-June-2011. How can I order these lists by date? I wrote I function like that :
public Cursor getAll(){
return (mDb.rawQuery("SELECT _id, Title, Shop , Data , Budget_allocated ," +
" Budget_spent FROM Lists ORDER BY Data",null));
}
but it doesn't work fine. I think it compare only the day. For example, if I have 31-May-2011 and 6-June-2011, it will say that the first date is after the second date.
It is possible what I am trying to do? Should I modify the date in format like this :6-06-2011?
Thanks..
I don't know anything about android development, but it sounds like your date field is stored as a string rather than a date, is that correct?
If so, you can either:
Change your table so that field is a date (then it should compare correctly)
Or store it in a standard format such that the default string comparison sorts dates correctly. Since string comparison sorts first on first character, second on second character, etc, this would be putting the biggest time difference first, ie. "2011-05-31" (include the zeroes).
(You should be able to convert the field by making a new field, copying the data from the old field into the new field in the correct format, and then deleting the old field and renaming the new one, or more simply if you simply want to change the format of the text. You should be able to do this either from code, or with an "update" query, AFAIK.)
Use a date format as follows...yyyy-MM-dd HH:mm:ss. This is guaranteed to be sortable in ascending or descending order.
If your Data column is not of type datetime there may be an issue. Take a look at this related SO question and answers:
SQL ORDER BY date problem