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))
Related
Say I have a RecyclerView and I'm populating it with an object.
And the object has a date field, and when a new date is reached, a standalone header is created with that date, and then the item is added.
The following objects with the same date will not create a new header, unless it's a new date.
Is it possible to do this (maybe using getItemViewType), while also being compatible with ItemTouchHelper?
So, if I remove the last item under a header at runtime, it'll also remove the header?
Also can I make the header not swipeable?
Other SO-posts solutions, as far as I understand, expect that the header information will come as part of the list input, while I want it to be based on the date of the objects.
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.
I use Parse.com as backend, and I want work with calendarview in order to let the users select a range of dates and store them in parse. Then I will retrieve that information to set it in a differen CalendarView. I am using CalendarListView explained here
Now in the sample they provide I see this method:
#Override
public void onDateRangeSelected(SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> selectedDays)
{
Log.e("Date range selected", selectedDays.getFirst().toString() + " --> " + selectedDays.getLast().toString());
}
So if I want to store that in parse, should I use an Array, how do I store secteddays in parse.
There is another library that I was trying to use, here which is similar to the previous and its method to get selected days is:
#Override
public void alertSelectedFail(FailEven even) {
Toast.makeText(context, "alertSelectedFail", Toast.LENGTH_SHORT).show();
}
So As you can see I can get a List of dates from this method, so how do I storage that in Parse? Should I convert that in Array? if yes How do I do it?
And once I do it I want to retrieve that and set it in a different Calendarview just to show. Plaese I am new at android, hope somebody can help.
The selectedDays returns SelectedDays<CalendarDay> That contains only the first and last CalendarDay
Seems the solutions is to manually get all days in between. See genarate dates between two date in android answer to get a List<Date>
Then if you want to make an array out of that you can use the following:
dates[] array = new Date[list.size()];
list.toArray(array); // fill the array
Maybe you also need DateFormatter to correctly formate the date. Or once you have the List<Date> You can also just loop through the list and save them in a String array one by one by using the toString() method on the date.
I have this problem. I read with BufferedReader text from one system file, this text contains for example 5 WORDS, but in another case it can contain less or more words, then I put this text (these words) to ONE string and save that string to shared preferences. Then I make spinner from this string,
Code here:
Spinner spinner = new Spinner(this);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, yourString.split(" "));
spinner.setAdapter(spinnerArrayAdapter);
And now if for example spinner contains 5 options (5 words) and user select some of these words, I need to put this word to one system file. I use echo command for insertion. So the best thing would be if I could save chosen word from spinner to shared preferences as string. I use if(possition==0) for selection in normal spinner, but I think it's not possible to use it in this case.
Could anybody help me?
you can get selected text by writing this line of code
spinner.getSelectedItem().toString();
SharedPreferences pref = getSharedPreferences(
"Preferences", 0);
SharedPreferences.Editor edit = pref.edit();
edit.putString("ABC", spinner.getSelectedItem().toString());
edit.commit();
not getting your complete idea what you want to do...
but i think you want to get text which is selected in the spinner, then split your string in one array pass this array in your spinner adapter.
After that use onItemSelection method, In this method u will get position and fetch the corresponding record from your array.
Try using the getPosition() method on the ArrayAdapter.
spinnerArrayAdapter.getPosition(savedstring);
If the saved string is in the array second time in then you can call setSelection() to that position otherwise let the user know (e.g. via Toast) that the previous selection is no longer valid.
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