我的应用程序包含日期选择器选项。当用户选择特定日期时,当天存在的数据应显示在选项卡内容上。我成功地解析了来自 JSON 的数据,但我不知道如何用日期解析数据。请帮助我。谢谢你
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setCurrentDateOnView();
addListenerOnButton();
TabHost tabHost = getTabHost();
// vehicle Tab
TabSpec vehicleSpec = tabHost.newTabSpec(VEHICLE_SPEC);
// Tab Icon
vehicleSpec.setIndicator(VEHICLE_SPEC, getResources().getDrawable(R.drawable.v));
Intent vehicleIntent = new Intent(this, vehicle.class);
// Tab Content
vehicleSpec.setContent(vehicleIntent);
// driver Tab
TabSpec driverSpec = tabHost.newTabSpec(DRIVER_SPEC);
// Tab Icon
driverSpec.setIndicator(DRIVER_SPEC, getResources().getDrawable(R.drawable.dr));
Intent driverIntent = new Intent(this, driver.class);
// Tab Content
driverSpec.setContent(driverIntent);
// ignition Tab
TabSpec ignitionSpec = tabHost.newTabSpec(IGNITION_SPEC);
// Tab Icon
ignitionSpec.setIndicator(IGNITION_SPEC, getResources().getDrawable(R.drawable.i));
Intent ignitionIntent = new Intent(this, ignition.class);
// Tab Content
ignitionSpec.setContent(ignitionIntent);
// activity Tab
TabSpec activitySpec = tabHost.newTabSpec(ACTIVITY_SPEC);
// Tab Icon
activitySpec.setIndicator(ACTIVITY_SPEC, getResources().getDrawable(R.drawable.activity));
Intent activityIntent = new Intent(this, activity.class);
// Tab Content
activitySpec.setContent(activityIntent);
// speed Tab
TabSpec speedSpec = tabHost.newTabSpec(SPEED_SPEC);
speedSpec.setIndicator(SPEED_SPEC, getResources().getDrawable(R.drawable.d));
Intent speedIntent = new Intent(this, speed.class);
speedSpec.setContent(speedIntent);
// idle Tab
TabSpec idleSpec = tabHost.newTabSpec(IDLE_SPEC);
idleSpec.setIndicator(IDLE_SPEC, getResources().getDrawable(R.drawable.idle));
Intent idleIntent = new Intent(this, idle.class);
idleSpec.setContent(idleIntent);
TabSpec distanceSpec = tabHost.newTabSpec(DISTANCE_SPEC);
distanceSpec.setIndicator(DISTANCE_SPEC, getResources().getDrawable(R.drawable.s));
Intent distanceIntent = new Intent(this, distance.class);
distanceSpec.setContent(distanceIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(distanceSpec); // Adding distance tab
tabHost.addTab(idleSpec); // Adding idle tab
tabHost.addTab(speedSpec); // Adding speed tab
tabHost.addTab(ignitionSpec); // Adding ignition tab
tabHost.addTab(driverSpec); // Adding driver tab
tabHost.addTab(vehicleSpec); // Adding vehicle tab
tabHost.addTab(activitySpec); // Adding activity tab
TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
final int tabChildrenCount = tabWidget.getChildCount();
View currentView;
for (int i = 0; i < tabChildrenCount; i++) {
currentView = tabWidget.getChildAt(i);
LinearLayout.LayoutParams currentLayout =
(LinearLayout.LayoutParams) currentView.getLayoutParams();
currentLayout.setMargins(10, 10, 10, 10);
}
tabWidget.requestLayout();
}
private void addListenerOnButton() {
// TODO Auto-generated method stub
dbtn1 = (Button) findViewById(R.id.dbtn1);
dbtn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
}
private void setCurrentDateOnView() {
// TODO Auto-generated method stub
tvDisplayDate = (TextView) findViewById(R.id.tvDate);
dpResult = (DatePicker) findViewById(R.id.dpResult);
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
// set current date into textview
tvDisplayDate.setText(new StringBuilder()
// Month is 0 based, just add 1
.append(month + 1).append("-").append(day).append("-")
.append(year).append(" "));
// set current date into datepicker
dpResult.init(year, month, day, null);
}
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
// set date picker as current date
return new DatePickerDialog(this, datePickerListener,
year, month,day);
}
return null;
}
private DatePickerDialog.OnDateSetListener datePickerListener
= new DatePickerDialog.OnDateSetListener() {
// when dialog box is closed, below method will be called.
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
year = selectedYear;
month = selectedMonth;
day = selectedDay;
// set selected date into textview
tvDisplayDate.setText(new StringBuilder().append(month + 1)
.append("-").append(day).append("-").append(year)
.append(" "));
// set selected date into datepicker also
dpResult.init(year, month, day, null);
}
};
}
我的 json ......它每天在服务器中更新
{"results" :[{"id":"34492","vehicle_name":"Innova","driver_name":"Mahesh","coordinates":"17.3510,78.5561","location_name":"Sai Soba Construction, Central Bank Colony, LB Nagar, Hyderabad, Andhra Pradesh 500074, India","speed":"2","posted_on":"2013-04-24 10:33:40","created_on":"2013-04-24 10:33:53"}