1. Download our Official Android App: Forums for Android!

Apps Help with my code

Discussion in 'Android Development' started by NHLFLASH, Jun 7, 2011.

  1. NHLFLASH

    NHLFLASH Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jun 4, 2011

    Jun 4, 2011
    5
    0
    5
    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
     

    Attached Files:


    Advertisement

  2. alostpacket

    alostpacket Over Macho Grande?
    Rank:
    None
    Points:
    513
    Posts:
    7,972
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,972
    3,603
    513
    Android App Developer
    NY
    Moved to app dev forum, you'll find more help here I believe.
     
  3. JiMMaR

    JiMMaR Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    363
    Joined:
    Jun 12, 2010

    Jun 12, 2010
    363
    57
    53
    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
     
  4. NHLFLASH

    NHLFLASH Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jun 4, 2011

    Jun 4, 2011
    5
    0
    5
    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 (Text):
    1. import java.util.Calendar;
    2.  
    3. import android.app.Activity;
    4. import android.app.DatePickerDialog;
    5. import android.app.Dialog;
    6. import android.os.Bundle;
    7. import android.util.Log;
    8. import android.view.View;
    9. import android.widget.Button;
    10. import android.widget.DatePicker;
    11. import android.widget.TextView;
    12.  
    13. public class DatePickerActivity extends Activity {
    14.     private static final String TAG = DatePicker.class.getSimpleName();
    15.     private TextView mDateDisplay;
    16.     private Button mPickDate;
    17.     private int mYear;
    18.     private int mMonth;
    19.     private int mDay;
    20.  
    21.     static final int DATE_DIALOG_ID = 0;
    22.  
    23.     public void onCreate(Bundle savedInstanceState) {
    24.         super.onCreate(savedInstanceState);
    25.         setContentView(R.layout.newproject);
    26.         /**
    27.          *
    28.          * DATE PICKER
    29.          *
    30.          */
    31.  
    32.         // capture our View elements
    33.         mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
    34.         mPickDate = (Button) findViewById(R.id.ButtonpickDate);
    35.  
    36.         // add a click listener to the button
    37.         mPickDate.setOnClickListener(new View.OnClickListener() {
    38.             public void onClick(View v) {
    39.                 showDialog(DATE_DIALOG_ID);
    40.                
    41.                 Log.d(TAG, "onClick'd DatePicker");
    42.             }
    43.         });
    44.  
    45.         // get the current date
    46.         final Calendar c = Calendar.getInstance();
    47.         mYear = c.get(Calendar.YEAR);
    48.         mMonth = c.get(Calendar.MONTH);
    49.         mDay = c.get(Calendar.DAY_OF_MONTH);
    50.  
    51.         // display the current date (this method is below)
    52.         updateDisplay();
    53.     }
    54.  
    55.     // updates the date in the TextView
    56.     private void updateDisplay() {
    57.         mDateDisplay.setText(new StringBuilder()
    58.                 // Month is 0 based so add 1
    59.                 .append(mMonth + 1).append("-").append(mDay).append("-")
    60.                 .append(mYear).append(" "));
    61.     }
    62.  
    63.     // the callback received when the user "sets" the date in the dialog
    64.     private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
    65.  
    66.         public void onDateSet(android.widget.DatePicker view, int year,
    67.                 int monthOfYear, int dayOfMonth) {
    68.             mYear = year;
    69.             mMonth = monthOfYear;
    70.             mDay = dayOfMonth;
    71.             updateDisplay();
    72.         }
    73.     };
    74.  
    75.     @Override
    76.     protected Dialog onCreateDialog(int id) {
    77.         switch (id) {
    78.         case DATE_DIALOG_ID:
    79.             return new DatePickerDialog(this, mDateSetListener, mYear,
    80.                     mMonth, mDay);
    81.         }
    82.         return null;
    83.     }
    84.  
    85.  
    86. }
    87.  


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

    Code (Text):
    1.    
    2.  
    3.         Button buttonDatePicker = (Button) findViewById(R.id.ButtonpickDate);
    4.         buttonDatePicker.setOnClickListener(DatePicker);
    5.  
    6.  
    7.     private OnClickListener DatePicker = new OnClickListener() {
    8.  
    9.         @Override
    10.         public void onClick(View v) {
    11.             Intent intent = new Intent();
    12.             intent.setClass(NewProjectActivity.this, DatePickerActivity.class);
    13.             startActivity(intent);
    14.            
    15.             Log.d(TAG, "on Click'd, DatePicker");
    16.         }
    17.     };
     

Share This Page

Loading...