Getting EditText Value from a Fragment in main Activity

后端 未结 3 1075
攒了一身酷
攒了一身酷 2021-01-26 02:55

I have placed three edit text in a fragment and want to get the values of the edit text in the fragment from the main activity. I tried the following code but its throwing

3条回答
  •  一个人的身影
    2021-01-26 03:12

    I think you name, age, and gender views are not initialized: try changing your onCreateView() like this

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.frag1, container);
        name = (EditText) view.findViewById(R.id.your_id);
        age = (EditText) view.findViewById(R.id.your_id);
        gender = (EditText) view.findViewById(R.id.your_id);
    
        return view;
    }
    

提交回复
热议问题