• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Help with my code

NHLFLASH

Lurker
Hello all,

I have enclosed a zip with my eclipse project, and I was hoping I could get someone kind enough to help me with it. I am trying to make it so when I click the "add a date" button in New Project, the it will bring up the datepicker dialog box. When i click it, it brings me to the datepickerActivity class and then it allows me to choose a date. I also want to be able to choose a date and then click the button again and add another date, but that is after i get the button working correctly in the first place. Thanks to all who help.

Mike
 

Attachments

here's a tip , don't give ppl your code in zip files , if you need help then post your work using the [ CODE] tag and only put the part where you have a problem with
don't expect us to download your whole project and look inside the classes (even if it was one class , I wouldn't know cause I won't download it) and look for the problem

currently I doubt you'll get much help
 
thanks alot, I originally had this in the wrong forum so I wasnt sure how I should have presented it. I appreciate the constructive critisism. Ill explain a little more about my problem. I have a view that opens up and it has a a datepicker button and a confirm button. the confirm button switches to another activity. I created a datepicker class and i added a onclick() to my first view, but now on the first click, the datepicker button is working as my confirm button, and my confirm button down nothing. When i click a second time, it opens up the datepicker dialog.


DatepickeActivity.java class

Code:
import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

public class DatePickerActivity extends Activity {
	private static final String TAG = DatePicker.class.getSimpleName();
	private TextView mDateDisplay;
	private Button mPickDate;
	private int mYear;
	private int mMonth;
	private int mDay;

	static final int DATE_DIALOG_ID = 0;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.newproject);
		/**
		 * 
		 * DATE PICKER
		 * 
		 */

		// capture our View elements
		mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
		mPickDate = (Button) findViewById(R.id.ButtonpickDate);

		// add a click listener to the button
		mPickDate.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				showDialog(DATE_DIALOG_ID);
				
				Log.d(TAG, "onClick'd DatePicker");
			}
		});

		// get the current date
		final Calendar c = Calendar.getInstance();
		mYear = c.get(Calendar.YEAR);
		mMonth = c.get(Calendar.MONTH);
		mDay = c.get(Calendar.DAY_OF_MONTH);

		// display the current date (this method is below)
		updateDisplay();
	}

	// updates the date in the TextView
	private void updateDisplay() {
		mDateDisplay.setText(new StringBuilder()
				// Month is 0 based so add 1
				.append(mMonth + 1).append("-").append(mDay).append("-")
				.append(mYear).append(" "));
	}

	// the callback received when the user "sets" the date in the dialog
	private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {

		public void onDateSet(android.widget.DatePicker view, int year,
				int monthOfYear, int dayOfMonth) {
			mYear = year;
			mMonth = monthOfYear;
			mDay = dayOfMonth;
			updateDisplay();
		}
	};

	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case DATE_DIALOG_ID:
			return new DatePickerDialog(this, mDateSetListener, mYear,
					mMonth, mDay);
		}
		return null;
	}


}



this is the onclick method i used in the other class:

Code:
		Button buttonDatePicker = (Button) findViewById(R.id.ButtonpickDate);
		buttonDatePicker.setOnClickListener(DatePicker);


	private OnClickListener DatePicker = new OnClickListener() {

		@Override
		public void onClick(View v) {
			Intent intent = new Intent();
			intent.setClass(NewProjectActivity.this, DatePickerActivity.class);
			startActivity(intent);
			
			Log.d(TAG, "on Click'd, DatePicker");
		}
	};
 
Back
Top Bottom