private static String[] BFROM ={PHONENUM, MESSAGE, TIME, ISREAD, CABINETCODE};
private static int[] BTO = {R.id.toptext, R.id.bottomtext, R.id.time,};
private void showBinding(Cursor cursor) {
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, BFROM, BTO);
setListAdapter(adapter);
}
위 소스를 사용을 해서 ListView 에 바인딩을 하는데 시간을 디비에
System.currentTimeMillis() 식으로 저장을 해서 화면에 보여 지는 것은 123456789 로 보여집니다.
제가 원하는 것은 2009-12-30 12:12 분으로 보여주고 싶습니다..
혹시 방법이 없을까요? 아시는 분은 한수 지도 부탁 드립니다...
그냥 디비에 2009-12-30 12:12 식으로 저장을 해야 되나요? --;
수고하세요..
여기 계시는 많은 개발자님의 도움으로 Custom Adapter 를 만들어서 해결을 했습니다..
//SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, BFROM, BTO);
//setListAdapter(adapter);
SmsCursorAdapter adapter = new SmsCursorAdapter(this, R.layout.item, cursor, BFROM, BTO);
setListAdapter(adapter);
public class SmsCursorAdapter extends SimpleCursorAdapter {
public SmsCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
// TODO Auto-generated constructor stub
this.setViewBinder(new SmsViewBinder());
}
}
public class SmsViewBinder implements ViewBinder {
private static final String TAG = "SmsViewBinder";
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
// TODO Auto-generated method stub
Log.d(TAG, "view:" + ((TextView)view).getId() + "/R.id.time:" + R.id.time + "/columnIndex:" + columnIndex );
if(view instanceof TextView) {
if(((TextView)view).getId() == R.id.time) {
long receiveTime = cursor.getLong(columnIndex);
Date date = new Date(receiveTime);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy:MM.dd HH:mm:ss");
String smstime = dateFormat.format(date);
((TextView)view).setText(smstime);
return true;
}
}
return false;
}
}
long temp = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String time = sdf.format(new Date(temp));