简体   繁体   中英

How can I add button function into fragments

I'm trying to create a learning application the activity will show 3 tabs, my question is how can I put a Video View into the tab. The codes for the button that I know doesn't work. any idea about what syntax should I use when it comes to fragments? enter image description here

Do something like this

Public class  Tab2Vid extand Fragment implement View.OnClickListener {

    Public View onCreateView(LayoutInflater inflater, ViewGroup container
                            ,Bundle savedlnstanceState) {

    View rootView = inflater.inflate(R.layout.tab2video, container, false); 

    Button play = (Button)rootView.findViewById(R.id.btnplay);

    return rootView; 

    }

    Public void onClick(View view)( 
    switch (view.getId())
        {

            case R.id.btnplay:
              Toast.makeText(getActivity(),"Btn Play clicked", Toast.LENGTH_SHORT).show();
                break;
            default:
                return;
        }
    } 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM