Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
findviewbyid在公共静态类android java中不起作用_Java_Android_Static Classes - Fatal编程技术网

findviewbyid在公共静态类android java中不起作用

findviewbyid在公共静态类android java中不起作用,java,android,static-classes,Java,Android,Static Classes,我想将从用户处获得的值放入“OnDataSet”函数中的EditText,而findviewbyid中有一个错误,可能是因为您尚未将其键入EditText。 EditText-dob=(EditText)findViewById(R.id.dob) 可能是因为您尚未将其类型转换为EditText。 EditText-dob=(EditText)findViewById(R.id.dob) 如果您想在静态中findviewById,您应该调用rootView public static class

我想将从用户处获得的值放入
“OnDataSet”
函数中的EditText,而
findviewbyid
中有一个错误,可能是因为您尚未将其键入EditText。
EditText-dob=(EditText)findViewById(R.id.dob)

可能是因为您尚未将其类型转换为EditText。
EditText-dob=(EditText)findViewById(R.id.dob)

如果您想在静态
findviewById
,您应该调用
rootView

public static class DatePickerFragment extends DialogFragment
            implements DatePickerDialog.OnDateSetListener {

        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            // Use the current date as the default date in the picker
            final Calendar c = Calendar.getInstance();
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH);
            int day = c.get(Calendar.DAY_OF_MONTH);

            // Create a new instance of DatePickerDialog and return it
            return new DatePickerDialog(getActivity(), this, year, month, day);
        }

        public void onDateSet(DatePicker view, int year, int month, int day) {
            EditText dob = findViewById(R.id.dob);
        }
    }
    public void showDatePickerDialog(View v) {
        DialogFragment newFragment = new DatePickerFragment();
        newFragment.show(getSupportFragmentManager(), "datePicker");
    }
** 为了便于工作,您可以使用此库

有关更多信息:


  • 如果您想在
    static
    findviewById
    ,您应该调用
    rootView

    public static class DatePickerFragment extends DialogFragment
                implements DatePickerDialog.OnDateSetListener {
    
            @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                // Use the current date as the default date in the picker
                final Calendar c = Calendar.getInstance();
                int year = c.get(Calendar.YEAR);
                int month = c.get(Calendar.MONTH);
                int day = c.get(Calendar.DAY_OF_MONTH);
    
                // Create a new instance of DatePickerDialog and return it
                return new DatePickerDialog(getActivity(), this, year, month, day);
            }
    
            public void onDateSet(DatePicker view, int year, int month, int day) {
                EditText dob = findViewById(R.id.dob);
            }
        }
        public void showDatePickerDialog(View v) {
            DialogFragment newFragment = new DatePickerFragment();
            newFragment.show(getSupportFragmentManager(), "datePicker");
        }
    
    ** 为了便于工作,您可以使用此库

    有关更多信息:


  • 这是我写的答案

    rootView.findViewById
    
    onDateSet中的更改

    public static class DatePickerFragment extends DialogFragment
                implements DatePickerDialog.OnDateSetListener {
    
            @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                // Use the current date as the default date in the picker
                final Calendar c = Calendar.getInstance();
                int year = c.get(Calendar.YEAR);
                int month = c.get(Calendar.MONTH);
                int day = c.get(Calendar.DAY_OF_MONTH);
    
                // Create a new instance of DatePickerDialog and return it
                return new DatePickerDialog(getActivity(), this, year, month, day);
            }
    
            public void onDateSet(DatePicker view, int year, int month, int day) {
                EditText dob = getActivity().findViewById(R.id.dob);
                dob.setText(day+"/"+month+"/"+year);
            }
        }
    

    这是我写的答案

    rootView.findViewById
    
    onDateSet中的更改

    public static class DatePickerFragment extends DialogFragment
                implements DatePickerDialog.OnDateSetListener {
    
            @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                // Use the current date as the default date in the picker
                final Calendar c = Calendar.getInstance();
                int year = c.get(Calendar.YEAR);
                int month = c.get(Calendar.MONTH);
                int day = c.get(Calendar.DAY_OF_MONTH);
    
                // Create a new instance of DatePickerDialog and return it
                return new DatePickerDialog(getActivity(), this, year, month, day);
            }
    
            public void onDateSet(DatePicker view, int year, int month, int day) {
                EditText dob = getActivity().findViewById(R.id.dob);
                dob.setText(day+"/"+month+"/"+year);
            }
        }
    

    欢迎光临,记住巴特霍夫是非常好的图书馆欢迎光临,记住巴特霍夫是非常好的图书馆