Fragment implements OnClickListener

后端 未结 4 833
醉话见心
醉话见心 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 06:55

    Just do one this

    public class fragmentOne extends Fragment implements OnClickListener {
        Button myButton;
    
        @Override
        public View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedinstanceState) {
            View myView = inflater.inflate(R.layout.fragment_1, container, false);
            myButton = (Button) myView.findViewById(R.id.myButton);
            myButton.setOnClickListener(this);
            return myView;
        }
    
        @Override
        public void onClick(View v) {
            // implements your things
        }
    }
    

    very simple

提交回复
热议问题