| Author |
Message |
iPaul Pro Developer

Joined: 15 Mar 2009 Posts: 33
|
Posted: Sat Mar 28, 2009 4:38 pm Post subject: Formatting CallLog Date and Time (Absolute) |
|
|
Okay, So I found out that using FormatDate (SimpleDateFormat) is not preferred for loops with a lot of information (that is why my app was taking so long to load)
I have found alternatives.
For absolute date and time, try this (not sure if this is the best way but it works and is fast):
| Java: |
long created = c.getLong(dateColumn);
Date nDate = new Date(created);
Calendar cal = Calendar.getInstance();
cal.setTime(nDate);
int iMonth = cal.get(Calendar.MONTH) + 1;
int iDay = cal.get(Calendar.DAY_OF_MONTH);
int iDayName = cal.get(Calendar.DAY_OF_WEEK);
int iHour = cal.get(Calendar.HOUR);
int iMin = cal.get(Calendar.MINUTE);
int iAmPm = cal.get(Calendar.AM_PM);
String month = Integer.toString(iMonth);
if(iMonth == 1){
month = "January";
}
if(iMonth == 2){
month = "February";
}
if(iMonth == 3){
month = "March";
}
if(iMonth == 4){
month = "April";
}
if(iMonth == 5){
month = "May";
}
if(iMonth == 6){
month = "June";
}
if(iMonth == 7){
month = "July";
}
if(iMonth == 8){
month = "August";
}
if(iMonth == 9){
month = "September";
}
if(iMonth == 10){
month = "October";
}
if(iMonth == 11){
month = "November";
}
if(iMonth == 12){
month = "December";
}
String dayName = Integer.toString(iDayName);
if(iDayName == 1){
dayName = "Sunday";
}
if(iDayName == 2){
dayName = "Monday";
}
if(iDayName == 3){
dayName = "Tuesday";
}
if(iDayName == 4){
dayName = "Wednesday";
}
if(iDayName == 5){
dayName = "Thursday";
}
if(iDayName == 6){
dayName = "Friday";
}
if(iDayName == 7){
dayName = "Saturday";
}
String day = Integer.toString(iDay);
if(iDay < 10){
day = "0" + day;
}
String hour = Integer.toString(iHour);
if(iHour == 0){
hour = "12";
}
String min = Integer.toString(iMin);
if(iMin < 10){
min = "0" + min;
}
String amPm = Integer.toString(iAmPm);
if(iAmPm == 0){
amPm = "AM";
} else {
amPm = "PM";
}
String myDate = dayName + ", " + month + " " + day + "," + " " + cal.get(Calendar.YEAR);
String myTime = hour + ":" + min + " " + amPm;
callList.add(new IconifiedText(callerName, callerPhoneNumber, myDate, myTime, currentIcon)); |
This is will ouput the date like so: Saturday, March 28, 2009
and the time: 11:30 AM
IMPORTANT - I have modified the IconifiedTextListAdapter.java, IconifiedText.java, and IconifiedTextView.java to accept the extra "myDate" and "myTime" views. This must be done first, if you wish to implement my date and time fix (HINT - just 'duplicate' the existing TextViews).
If anyone needs help on making this work, feel free to ask me how to do it. I promise to answer, whether or not I know how to help.
I have a solution for relative dates and times, however it requires a ViewBinder and SimpleCursorAdapter to be used, and I have yet to figure out how to incorporate with the IconifiedTextListAdapter.
Hope this helps someone.
- iPaul Pro |
|
| Back to top |
|
 |
|
|
 |
iPaul Pro Developer

Joined: 15 Mar 2009 Posts: 33
|
Posted: Sat Mar 28, 2009 10:10 pm Post subject: Set an ACTION_CALL Intent to onListItemClick |
|
|
Hello again,
I'm trying to make an onListItemClick that would call the Calls.NUMBER of the selected list row. Here's what I have (after onCreate):
| Java: |
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(Intent.ACTION_CALL);
Cursor c = (Cursor) ((IconifiedTextListAdapter)getListAdapter()).getItem(position);
long phoneNum = c.getLong(c.getColumnIndex(Calls.NUMBER));
i.setData(ContentUris.withAppendedId(
android.provider.CallLog.Calls.CONTENT_URI, phoneNum));
this.startActivity(i);
}
|
Any help, hints, or links would be greatly appreciated.
Thanks |
|
| Back to top |
|
 |
iPaul Pro Developer

Joined: 15 Mar 2009 Posts: 33
|
Posted: Tue Apr 07, 2009 5:58 pm Post subject: |
|
|
How can I set and onListItemClick to load an intent, bundling the callerName variable?
Here's what I've tried:
1. | Java: |
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(this, MyActivity.class);
Cursor cursor = (Cursor) itla.getItem(position);
Bundle b = new Bundle();
String cCallerName = cursor.getString(cursor.getColumnIndex(Calls.CACHED_NAME));
b.putString("CallerName", cCallerName);
intent.putExtras(b);
startActivity(intent);
} |
- Force close,
2. | Java: |
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(this, MyActivity.class);
Cursor cursor = (Cursor) ((IconifiedTextListAdapter)getListAdapter()).getItem(position);
Bundle b = new Bundle();
String cCallerName = cursor.getString(cursor.getColumnIndex(Calls.CACHED_NAME));
b.putString("CallerName", cCallerName);
intent.putExtras(b);
startActivity(intent);
}
|
- again, force close.
3. | Java: |
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(this, MyActivity.class);
c = (Cursor) ((IconifiedTextListAdapter)getListAdapter()).getItem(position);
Bundle b = new Bundle();
String cCallerName = c.getString(c.getColumnIndex(Calls.CACHED_NAME));
b.putString("CallerName", cCallerName);
intent.putExtras(b);
startActivity(intent);
} |
- you guessed it.
4. | Java: |
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(this, MyActivity.class);
c = (Cursor) itla.getItem(position);
Bundle b = new Bundle();
b.putString("CallerName", callerName);
intent.putExtras(b);
startActivity(intent);
} |
- Nope.
Now I am still new to Java/Android and do not fully understand how to debug using my LogCat output.
When I try to bundle the variable, without getting the item postition, it works, but only display the name from the first database result (oldest call):
| Java: |
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(this, MyActivity.class);
Bundle b = new Bundle();
b.putString("CallerName", callerName);
intent.putExtras(b);
startActivity(intent);
} |
So my issue definitely lies in my attempt to getItem(position) of the IconifiedTextListAdapter.
I've tried many things beyond whats posted above like closing the first cursor, trying to addExtra to the intent without a bundle. Nothing works.
Please, any help would be greatly appreciated. |
|
| Back to top |
|
 |
iPaul Pro Developer

Joined: 15 Mar 2009 Posts: 33
|
Posted: Sun Apr 12, 2009 8:20 am Post subject: |
|
|
Is there anyone that can help me figure out how to correctly bundle cursor items from the IconifiedTextListAdapter?
I'd like to know how to pass the "cached name" of the selected list item to a sub-activity using an onListItemClick.
I have no problem bundling static string between activities. It is only when I try to pass the position of the list adapter that I run into issues.
The second activity could literally just display the bundled string(s) in a simple, un-styled text view.
Please, I have been stuck on this for days. Any help or links greatly appreciated.
Please.. |
|
| Back to top |
|
 |
iPaul Pro Developer

Joined: 15 Mar 2009 Posts: 33
|
Posted: Fri Apr 17, 2009 7:49 pm Post subject: |
|
|
I figured it out. This topic title should be changed to the "iPaul Pro Trial and Error Thread"
To pass the position of the cursor items from the IconifiedTextListAdapter to a sub-activity (Pass the chosen Name):
In CallLogDisplayer.java:
before OnCreate
| Java: | private Cursor c = null; |
(then remove the Cursor declaration at the query)
after OnCreate
| Java: |
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
c.moveToPosition(position);
Intent i = new Intent(this, SubActivity.class);
i.putExtra("CallerName", c.getString(nameColumn));
startActivity(i);
} |
and in your SubActivity.java:
| Java: | String name = getIntent().getStringExtra("CallerName"); |
That's it! I was so close - but that's how these things go.
Feel free to ask for clarification.
- iPaul Pro |
|
| Back to top |
|
 |
sheshi85 Junior Developer

Joined: 08 Jun 2009 Posts: 15
|
Posted: Wed Jun 10, 2009 11:30 am Post subject: isFirst() is returning false always!!!!!!!!!!! |
|
|
I tried other methods like moveTofirst.but it is not showing the output in the emulator.can anyone please address this error!!!
thanks in advance!!!!!!!! |
|
| Back to top |
|
 |
|
|
 |
chico Once Poster

Joined: 17 Sep 2009 Posts: 1
|
Posted: Thu Sep 17, 2009 9:27 pm Post subject: Re: [VIDEO-Tut] - Querying and Displaying the CallLog |
|
|
Hi Plusminus,
great tutorial,
I had one question
I want to only checked for the missed calls that has NOT yet been checked by the user (new missed calls). The way you have the code right now it will always count ALL the missed calls that are present in the call log. What I mean is if there is a missed call and I see a missed call icon on my status bar. Once I look at the call log , the status bar icon is cleared. But when we use the code provided by you it will still notify the already "viewed missed call" as missed call.
Thanks in advance for your help
Chico |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
© 2007, Android Development Community
All rights reserved.
Powered by phpBB.
|