Hello stackoverflowers
. Say I have a database with a string filled with dates. Good?
Problem 1:
Like this:
2013-06-01
So I want to translate this date to String
Input:
Tue Mar 01 00:00:00 EET 2013
As an example .. So, how can I get the date output as follows:
Mar 2013. Here are my codes:
date = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH) .parse(mCursor.getString(mCursor .getColumnIndex(KEY_AVAILABILITYDATE))); list.add(date);
Task 2 (the first problem should be solved):
Of course, I want to sort the list into which I added the date.
So, I run this code:
Collections.sort(list);
But honestly, this is not right! he mixes up - indicates all errors.
Thanks for reading, I hope this is easy!
All codes:
public ArrayList<Date> GetValues() { ArrayList<Date> list = new ArrayList<Date>(); Date date; if (mCursor.moveToFirst()) { while (mCursor.isAfterLast() == false) { try { date = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH) .parse(mCursor.getString(mCursor .getColumnIndex(KEY_AVAILABILITYDATE))); list.add(date); } catch (ParseException e) {
After losing hope, I decided to show you all the codes:
Codes:
Database DbHelper = new Database( this.getSherlockActivity()).open(); ArrayList<Date> headers = DbHelper.GetValues(); HashSet<Date> hs = new HashSet<Date>(); hs.addAll(headers); headers.clear(); headers.addAll(hs); Collections.sort(header,dateComparator); Collections.reverse(headers);
I use a third-party library: StickyGridHeadersGridView , so here is my adapter:
@Override public int getCountForHeader(int header) { // TODO Auto-generated method stub return 1; } @Override public int getNumHeaders() { // TODO Auto-generated method stub return headers.size(); } @Override public View getHeaderView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if (convertView == null) { convertView = inflater.inflate(R.layout.header, parent, false); TextView tvheader = (TextView) convertView .findViewById(R.id.tvheader); String headertitle = headers.get(position).toString(); if (headertitle.contains("01 00:00:00 EET")) { headertitle = headertitle.replace("01 00:00:00 EET", ""); } if (headertitle.contains("01 00:00:00 EEST")) { headertitle = headertitle.replace("01 00:00:00 EEST", ""); } if (headertitle.contains("02 00:00:00 EET")) { headertitle = headertitle.replace("02 00:00:00 EET", ""); } if (headertitle.contains("02 00:00:00 EEST")) { headertitle = headertitle.replace("02 00:00:00 EEST", ""); } if (headertitle.contains("15 00:00:00 EET")) { headertitle = headertitle.replace("15 00:00:00 EET", ""); } // days if (headertitle.contains("Mon")) { headertitle = headertitle.replace("Mon", ""); } if (headertitle.contains("Tue")) { headertitle = headertitle.replace("Tue", ""); } if (headertitle.contains("Wed")) { headertitle = headertitle.replace("Wed", ""); } if (headertitle.contains("Thu")) { headertitle = headertitle.replace("Thu", ""); } if (headertitle.contains("Fri")) { headertitle = headertitle.replace("Fri", ""); } if (headertitle.contains("Sat")) { headertitle = headertitle.replace("Sat", ""); } if (headertitle.contains("Sun")) { headertitle = headertitle.replace("Sun", ""); } // months if (headertitle.contains("Jan")) { headertitle = headertitle.replace("Jan", "January"); } if (headertitle.contains("Feb")) { headertitle = headertitle.replace("Feb", "February"); } if (headertitle.contains("Mar")) { headertitle = headertitle.replace("Mar", "March"); } if (headertitle.contains("Apr")) { headertitle = headertitle.replace("Apr", "April"); } if (headertitle.contains("Jun")) { headertitle = headertitle.replace("Jun", "June"); } if (headertitle.contains("Jul")) { headertitle = headertitle.replace("Jul", "July"); } if (headertitle.contains("Aug")) { headertitle = headertitle.replace("Aug", "August"); } if (headertitle.contains("Sep")) { headertitle = headertitle.replace("Sep", "September"); } if (headertitle.contains("Oct")) { headertitle = headertitle.replace("Oct", "October"); } if (headertitle.contains("Nov")) { headertitle = headertitle.replace("Nov", "November"); } if (headertitle.contains("Dec")) { headertitle = headertitle.replace("Dec", "December"); } tvheader.setText(headertitle); }
However, now the results are all mixed up and lost! gridview is big and I only see:
September 2013 June 2013 July 2013
in each row. What can I do? Thanks