implementing OnClickListener for a fragment on android

前端 未结 4 1088
忘了有多久
忘了有多久 2021-01-05 10:18

I have a sliding menu project and inside home layout another layout is called as a fragment :

this is the HomeFragment.java :

package info.androidhiv         


        
4条回答
  •  醉话见心
    2021-01-05 10:53

            // Inflate the layout for this fragment in on create
    
             RelativeLayout mLinearLayout = (RelativeLayout) inflater.inflate(R.layout.fragment_a,
                    container, false);
             cd = new ConnectionDetector(getActivity());
    
    
    
    
    ImageButton mButton = (ImageButton) mLinearLayout.findViewById(R.id.imageButton1);
    mButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // here you set what you want to do when user clicks your button,
            // e.g. launch a new activity
    
            Toast.makeText(getActivity(),"Opening Maps",Toast.LENGTH_LONG).show();
    
    
        }
    });
    

    you can call this by view

提交回复
热议问题