views:

32

answers:

0

Hello all,

The datepicker runs without problem. But if the datepicker is under tabwidget, it failed. Anyone has experience on that ??? and how to solve it ??

public class TestActivity extends Activity implements OnClickListener{

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
    layout = new LinearLayout(this);  
        layout.setOrientation(LinearLayout.VERTICAL);
        date = new Button(this);

        date.setText("Choose Date");
        layout.addView(date,
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                                              LinearLayout.LayoutParams.WRAP_CONTENT));
        date.setOnClickListener(this);
        incomehelper = new FinanceHelper(this);
        chosenDate = incomehelper.getToday();
        setContentView(layout);

    }

    public void onClick(View v) 
    {
      showDialog(DATE_ID);
    }

    protected Dialog onCreateDialog(int id) 
    {
        Calendar cal = Calendar.getInstance();
        int calyear = cal.get(Calendar.YEAR);
        int calmonth = cal.get(Calendar.MONTH);
        int calday = cal.get(Calendar.DAY_OF_MONTH);

        switch (id) 
        {
            case DATE_ID:
               return new DatePickerDialog(this,  mDateSetListener,  calyear, calmonth, calday);
        }
            return null;
    }

    private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() 
    {
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) 
        {
           chosenDate = incomehelper.getSelectedDate(dayOfMonth,monthOfYear,year);
           Toast.makeText(TestActivity.this, "Date Selected is ="+chosenDate, Toast.LENGTH_SHORT).show();
        }
    };

}