Fragment implements OnClickListener

后端 未结 4 861
醉话见心
醉话见心 2020-12-29 06:19

I\'ve got an application that I\'m modernizing. One step of this process is changing to a Fragment based layout (using the Fragments from the support library). I converted m

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 07:13

    I will Focus to use the OnClick action for global access, You have to do like this is your project, Must Implement the View.OnClickListener, then Override the Method OnClick(), In OnCreateView() have to do like this button_submit.setOnClickListener(this); for the Views you need, Please see the below code for Clear Answer,Thankyou.

    public class New_Project extends Fragment implements View.OnClickListener{
    private View mView;
    private Button button_submit;
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_newproject, container,false);
        button_submit=(Button)mView.findViewById(R.id.button_submit);
        button_submit.setOnClickListener(this);
        return mView;
    }
    
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button_submit:
                //do your stuff
                break;
        }
    }
    

    }

提交回复
热议问题