コード例 #1
0
 @Override
 public void onClick(final View v) {
   final int vId = v.getId();
   final Bundle userData = new Bundle();
   userData.putInt(UserDataView, vId);
   switch (vId) {
     case R.id.tStartDate:
     case R.id.tEndDate:
       final DatePickerFragment dateFragment =
           DatePickerFragment.newInstance((Calendar) v.getTag(), userData);
       dateFragment.setOnDateSetListener(dpdfListener);
       dateFragment.show(getSupportFragmentManager(), DatePickerFragmentTag);
       break;
     case R.id.tStartTime:
     case R.id.tEndTime:
       final TimePickerFragment timeFragment =
           TimePickerFragment.newInstance((Calendar) v.getTag(), userData);
       timeFragment.setOnTimeSetListener(tpdfListener);
       timeFragment.show(getSupportFragmentManager(), TimePickerFragmentTag);
       break;
   }
 }
コード例 #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
      UserID = SyncHelper.createInstance(this).getUserId();
    } catch (Exception ex) {
      Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
      finish();
    }
    setContentView(R.layout.edit_item_activity);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    edName = (EditText) findViewById(R.id.edName);
    edDesc = (EditText) findViewById(R.id.edDesc);
    sPriority = (Spinner) findViewById(R.id.sPriority);
    sStatus = (Spinner) findViewById(R.id.sStatus);
    tStartDate = (TextView) findViewById(R.id.tStartDate);
    tStartTime = (TextView) findViewById(R.id.tStartTime);
    tEndDate = (TextView) findViewById(R.id.tEndDate);
    tEndTime = (TextView) findViewById(R.id.tEndTime);
    tStartDate.setOnClickListener(this);
    tStartTime.setOnClickListener(this);
    tEndDate.setOnClickListener(this);
    tEndTime.setOnClickListener(this);
    adPriority =
        new SimpleCursorAdapter(
            this,
            R.layout.support_simple_spinner_dropdown_item,
            null,
            new String[] {Database.Priority.C_NAME},
            new int[] {android.R.id.text1},
            0);
    adPriority.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sPriority.setAdapter(adPriority);
    adStatus =
        new SimpleCursorAdapter(
            this,
            R.layout.support_simple_spinner_dropdown_item,
            null,
            new String[] {Database.Status.NAME},
            new int[] {android.R.id.text1},
            0);
    adStatus.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sStatus.setAdapter(adStatus);
    Intent intent = getIntent();
    if (!Intent.ACTION_INSERT.endsWith(intent.getAction())) {
      id = intent.getData();
    } else {
      listID = intent.getStringExtra(Item.LISTID);
      Calendar cal = Calendar.getInstance();
      cal.set(Calendar.SECOND, 0);
      cal.set(Calendar.MILLISECOND, 0);
      tStartDate.setTag(cal);
      tStartDate.setText(sdfdate.format(cal.getTime()));
      tStartTime.setTag(cal);
      tStartTime.setText(sdftime.format(cal.getTime()));
      cal = Calendar.getInstance();
      cal.set(Calendar.SECOND, 0);
      cal.set(Calendar.MILLISECOND, 0);
      cal.add(Calendar.DAY_OF_MONTH, 1);
      tEndDate.setTag(cal);
      tEndDate.setText(sdfdate.format(cal.getTime()));
      tEndTime.setTag(cal);
      tEndTime.setText(sdftime.format(cal.getTime()));
    }

    final DatePickerFragment dateFragment =
        (DatePickerFragment) getSupportFragmentManager().findFragmentByTag(DatePickerFragmentTag);
    if (dateFragment != null) {
      dateFragment.setOnDateSetListener(dpdfListener);
    }
    final TimePickerFragment timeFragment =
        (TimePickerFragment) getSupportFragmentManager().findFragmentByTag(TimePickerFragmentTag);
    if (timeFragment != null) {
      timeFragment.setOnTimeSetListener(tpdfListener);
    }
    getSupportLoaderManager().initLoader(PriorityLoaderId, null, this);
  }