0

DatedrumPicker这个链接中找到了一个

我已经将它与我的应用程序集成,当我第一次打开它时效果很好,但是当我第二次打开它时,它不会在选择器中显示当前日期。

发现在DrumPickerActivity.java,第一次打开就onDateChangedListener进去了,第二次就没有了。

我不明白这个监听器是如何工作的?

这是活动的代码

public class DrumPickerActivity extends Activity {

String pday; 
Calendar calendar = Calendar.getInstance();
public static Context con;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.dateconversion);
    final TextView date = (TextView) findViewById(R.id.date);
 final String DATE_FORMAT = "%04d"
        +getString(R.string.year)
        +"%02d"
        +getString(R.string.month)
        +"%02d"
        +getString(R.string.day)
        ;
     Resources res= this.getResources();


    final String[] HijrimonthName = res.getStringArray(R.array.Month_ar);


    final int year = calendar.get(Calendar.YEAR);
    final int month = calendar.get(Calendar.MONTH);
    final int day = calendar.get(Calendar.DAY_OF_MONTH);

    final DateDrumPicker dPicker = (DateDrumPicker)    findViewById(R.id.datepicker);

dPicker.setOnDateChangedListener(new OnDateChangedListener() {
 @Override
public void onDateChanged(DatePicker view, int year,
                int monthOfYear, int dayOfMonth) {

 date.setText(String.format(DATE_FORMAT, year, monthOfYear,
                    dayOfMonth));
        }//end onDateChanged

    });
 }

谢谢

4

0 回答 0