1

日期选择器运行没有问题。但是如果日期选择器在 tabwidget 下,它就会失败。谁有这方面的经验???以及如何解决?

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();
        }
    };

}   
4

0 回答 0