I am using a datepicker to select my date, after which, it will store into my database as String.
Can I know how do I take out the date in my database as a String?
This is because, I need to do a summary page, that pass all the data into the next intent. Meaning, I need to pass the data from my view all into my summary page, in order to have all the data in summary page. This is to allow me to be able to filter our the date easily.
For example, if date - 27/12/2014, it will show the list of result.
I did a quick check on my data, to see if I'm able to check the result. I've put a datepicker in my summary.java, which is in the editText(monthDate), so if monthDate = bundleDate(which is all the data result that I pass from view all), it will start a new intent. Else, it will go to about page.
However, my code skips the IF part, even if I select the right date, it will go through the else if code and not the else code.
public class summary extends Activity {
static EditText monthDate;
TextView avgPrice;
TextView exFuel;
TextView avgFC;
Button doneButton;
Button exitButton;
private String bundleID;
private String bundleDate;
private String bundlePrice;
private String bundlePump;
private String bundleCost;
private String bundleOdometer;
private String bundlePreOdometer;
private String bundleFcon;
static final int DATE_DIALOG_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.summary);
monthDate = (EditText)findViewById(R.id.month);
avgPrice = (TextView)findViewById(R.id.showavfPriceTV);
exFuel = (TextView)findViewById(R.id.showexFuelTV);
avgFC = (TextView)findViewById(R.id.showavgFCTV);
doneButton = (Button)findViewById(R.id.doneBTN);
exitButton = (Button)findViewById(R.id.exitBTN);
Bundle takeBundledData = getIntent().getExtras();
// First we need to get the bundle data that pass from the UndergraduateListActivity
bundleID = takeBundledData.getString("clickedID");
bundleDate = takeBundledData.getString("clickedDate");
bundlePrice = takeBundledData.getString("clickedPrice");
bundlePump = takeBundledData.getString("clickedPump");
bundleCost = takeBundledData.getString("clickedCost");
bundleOdometer = takeBundledData.getString("clickedOdometer");
bundlePreOdometer = takeBundledData.getString("clickedpreOdometer");
bundleFcon = takeBundledData.getString("clickedFCon");
Log.d("SUMMARY","bundle : "+ takeBundledData);
monthDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// showDialog(DATE_DIALOG_ID);
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");
}
});
doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (monthDate.equals(bundleDate))
{
Log.d("TRYINGOUT","date : "+ bundleDate);
Intent intent=new Intent(getApplicationContext(),homeActivity.class);
startActivity(intent);
}
else
{
Intent intent=new Intent(getApplicationContext(),about.class);
startActivity(intent);
}
}
});
}
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
public EditText editText;
DatePicker dpResult;
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
//return new DatePickerDialog(getActivity(), (EditSessionActivity)getActivity(), year, month, day);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
monthDate.setText(String.valueOf(day) + "/"
+ String.valueOf(month + 1) + "/" + String.valueOf(year));
// set selected date into datepicker also
}}}