Android 日期选择器片段
如果我要导入V4,则在片段上会出现错误。但是,活动上没有错误。然而,如果我要导入非v4版本,片段就可以了。但是,该活动将不起作用 提前谢谢 马丁福碎片Android 日期选择器片段,android,android-fragments,datepicker,Android,Android Fragments,Datepicker,如果我要导入V4,则在片段上会出现错误。但是,活动上没有错误。然而,如果我要导入非v4版本,片段就可以了。但是,该活动将不起作用 提前谢谢 马丁福碎片 public class PatientInfoFragment extends Fragment{ DateDialogFragment frag; Button button; Calendar now; public static final String ARG_SECTION_NUMBER = "s
public class PatientInfoFragment extends Fragment{
DateDialogFragment frag;
Button button;
Calendar now;
public static final String ARG_SECTION_NUMBER = "section_number";
// DATABASE ADAPTOR
patientDbAdapter patientDB;
Context myContext;
String ID = "0";
// SPINNER AND SEARCH VIEW
private SearchView mSearchView;
private TextView mStatusView;
private Spinner locationSpinner;
// DATE SPINNER
private int mYear;
private int mMonth;
private int mDay;
private TextView mDateDisplay;
static final int DIALOG_ALERT = 1;
// declaration
private EditText patientInitial, dateOfDiagnosis, wardClinic;
private Spinner locSpinner;
private CheckBox history, physical;
private String siteLocation;
String patientKey = "com.example.app.datetime";
// Verification
Boolean fromBase = false;
//Data From PatientDetails
String strValue1 ;
String strValue2 ;
String strValue3 ;
String strValue4 ;
String strValue5 ;
String strValue6 ;
private String patientID;
static final int DATE_DIALOG_ID = 0;
View rootView;
public PatientInfoFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.activity_patient_info,
container, false);
history = (CheckBox) rootView.findViewById(R.id.checkbox_history);
physical = (CheckBox) rootView.findViewById(R.id.checkbox_physical);
patientInitial = (EditText) rootView.findViewById(R.id.InitialTextEdit);
locSpinner = (Spinner) rootView.findViewById(R.id.locationSpinner);
dateOfDiagnosis = (EditText) rootView.findViewById(R.id.showMyDate);
siteLocation = locSpinner.getSelectedItem().toString();
wardClinic = (EditText) rootView.findViewById(R.id.WardClinicTextEdit);
// listener for the Ward/ClinicSpinner
addListenerOnSpinnerItemSelection();
return rootView;
}
public void showDatePickerDialog(View v) {
// DialogFragment newFragment = new DatePickerFragment();
// newFragment.show(getFragmentManager(), "datePicker");
}
private void RetrieveDataFromDatabaseBasedOnID(String paramString) {
myContext = getActivity();
// Opening of database
patientDB = new patientDbAdapter(myContext);
patientDB.open();
ID = paramString;
Cursor mCursor = this.patientDB
.retrievePatientEntriesBasedOnID(paramString);
if ((mCursor != null) && (mCursor.getCount() > 0)) {
mCursor.moveToFirst();
mCursor.getString(0); // ID
this.strValue1 = mCursor.getString(1); // Initial
this.strValue2 = mCursor.getString(2);// Date
this.strValue3 = mCursor.getString(3);// SiteLocation
this.strValue4 = mCursor.getString(4);// WardClinic
this.strValue5 = mCursor.getString(5);// CheckBoxHistory
this.strValue6 = mCursor.getString(6);// CheckBoxPhysical
patientInitial = (EditText) rootView.findViewById(R.id.InitialTextEdit);
locSpinner = (Spinner) rootView.findViewById(R.id.locationSpinner);
dateOfDiagnosis = (EditText) rootView.findViewById(R.id.showMyDate);
siteLocation = locSpinner.getSelectedItem().toString();
wardClinic = (EditText) rootView.findViewById(R.id.WardClinicTextEdit);
history = (CheckBox) rootView.findViewById(R.id.checkbox_history);
physical = (CheckBox) rootView.findViewById(R.id.checkbox_physical);
patientInitial.setText(strValue1);
dateOfDiagnosis.setText(strValue2);
// ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
// R.array.location_arrays, android.R.layout.simple_spinner_item);
// int S = adapter.getPosition(strValue3);
// locSpinner.setSelection(S);
wardClinic.setText(strValue4);
if (strValue5.equals("Y")) {
history.setChecked(true);
}
if (strValue6.equals("Y")) {
physical.setChecked(true);
}
fromBase = true;
} else {
fromBase = false;
}
}
// Listen to the spinner Item Selection - Completed
public void addListenerOnSpinnerItemSelection() {
locationSpinner = (Spinner) rootView.findViewById(R.id.locationSpinner);
// locationSpinner.setOnItemSelectedListener(new
// CustomOnItemSelectedListener());
}
// Listen to the spinner
public void addListenerOnButton() {
// retrieveValue
locationSpinner = (Spinner) rootView.findViewById(R.id.locationSpinner);
}
public void openPatientSearch() {
Intent patientDetailsIntent = new Intent(myContext, PatientDetails.class);
//StartActivityForResult doesn't work for fragment
// PatientInfo.this.startActivityForResult(patientDetailsIntent, 1);
}
public void showDialog() {
FragmentTransaction ft = getFragmentManager().beginTransaction(); //get the fragment
frag = DateDialogFragment.newInstance(getActivity(), new DateDialogFragmentListener(){
public void updateChangedDate(int year, int month, int day){
button.setText(String.valueOf(month+1)+"-"+String.valueOf(day)+"-"+String.valueOf(year));
now.set(year, month, day);
}
}, now);
frag.show(ft, "DateDialogFragment");
}
public interface DateDialogFragmentListener{
//this interface is a listener between the Date Dialog fragment and the activity to update the buttons date
public void updateChangedDate(int year, int month, int day);
}
}
在两者中导入相同的片段类。错误是什么?
package com.medilearner.fragment;
import java.util.Calendar;
import com.medilearner.fragment.DatePickerActivity.DateDialogFragmentListener;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;
import android.widget.DatePicker;
public class DateDialogFragment extends DialogFragment {
public static String TAG = "DateDialogFragment";
static Context mContext; //I guess hold the context that called it. Needed when making a DatePickerDialog. I guess its needed when conncting the fragment with the context
static int mYear;
static int mMonth;
static int mDay;
static DateDialogFragmentListener mListener;
public static DateDialogFragment newInstance(Context context, DateDialogFragmentListener listener, Calendar now) {
DateDialogFragment dialog = new DateDialogFragment();
mContext = context;
mListener = listener;
mYear = now.get(Calendar.YEAR);
mMonth = now.get(Calendar.MONTH);
mDay = now.get(Calendar.DAY_OF_MONTH);
/*I dont really see the purpose of the below*/
Bundle args = new Bundle();
args.putString("title", "Set Date");
dialog.setArguments(args);//setArguments can only be called before fragment is attached to an activity, so right after the fragment is created
return dialog;
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new DatePickerDialog(mContext, mDateSetListener, mYear, mMonth, mDay);
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
mListener.updateChangedDate(year, monthOfYear, dayOfMonth);
}
};
}