괜찮 았던 Datepickerdialog 프래그먼트가 있습니다. 버튼을 클릭하면 datepickerdialog가 열리 며, 왼쪽에는 회 전자 날짜 선택이 있고 오른쪽에는 달력보기가 있습니다. 다른 장소에서안드로이드 - DatePickerDialogFragment에서 Calendarview를 제거하십시오.
내가 일정보기 부분은 표시와 회 전자해야 할 나 혼자 그냥 스피너 날짜 선택 부분을 원하는 한 곳에서 내 앱
가 표시합니다 (달력보기 부분은 제거되어야한다 또는 숨겨진) 날짜 선택을 숨기거나 제거해야합니다.
하지만 난
Method m = minDateSelector.getClass().getMethod("setCalendarViewShown", boolean.class);
m.invoke(dp, false);
같은 달력보기를 숨기는 같은 다양한 것들로 많이 시도하지만 난이를 추가 할 때 나는 오류만을 얻을 ...이 사람이 너무 Datepicker created with DialopFragment showing Calender also
에 대한 이같은 문제
내 코드는,369 DatePickerActivity.java
입니다
import java.util.Calendar;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class DatePickerActivity extends Activity {
DateDialogFragment frag;
Button button;
Calendar now;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
now = Calendar.getInstance();
button = (Button)findViewById(R.id.date_button);
button.setText(String.valueOf(now.get(Calendar.MONTH)+1)+"-"+String.valueOf(now.get(Calendar.DAY_OF_MONTH))+"-"+String.valueOf(now.get(Calendar.YEAR)));
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog();
}
});
}
public void showDialog() {
FragmentTransaction ft = getFragmentManager().beginTransaction(); //get the fragment
frag = DateDialogFragment.newInstance(this, 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);
}
}
DateDialogFragment.java
import java.util.Calendar;
import com.zeroe.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", "Choose 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);
}
};
}
main.xml에 내가 날짜 선택기 대화 상자 조각 사용했다
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/date_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="03-18-2012"
android:onClick="clickMe"/>
</LinearLayout>
DatePicker에서 setCalendarViewShown 설정() 효과가 없습니다 :
여기 내 코드입니다. 달력보기에는 숨겨진 로그가 없습니다. https://code.google.com/p/android/issues/detail?id=80555를 참조하십시오. – josketres