当前位置: 首页 > 知识库问答 >
问题:

mcontext.get().getApplicationContext()和getActivity()之间的区别

苏富
2023-03-14
mDobPickerDialog = new DatePickerDialog(getActivity(), new OnDateSetListener() {

            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Calendar newDate = Calendar.getInstance();
                newDate.set(year, monthOfYear, dayOfMonth);
                mDobEditText.setText(mDateFormatter.format(newDate.getTime()));
            }

        },newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
private Context mContext;

public DisplayProfileFragment(Context context) {
        super();
        mContext = context;
    }

共有1个答案

呼延弘方
2023-03-14

getActivity()返回与片段关联的活动。

http://developer.android.com/reference/android/app/fragment.html#GetActivity()

getApplicationContext()返回全局应用程序上下文。

 类似资料: