toolbar menu item click in fragments

后端 未结 4 1932
鱼传尺愫
鱼传尺愫 2021-01-01 17:45

I know this question has been asked and but I am unable to solve my problem after looking at those answer. I have an Activity with a Fragment. In fragment, I have added the

4条回答
  •  攒了一身酷
    2021-01-01 18:36

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
     {
       View v = inflater.inflate(R.layout.training1_fragment, container, 
                  false);
    
           setHasOptionMenu(true);
    
           return v;
     }
    
    @Override
     public boolean onOptionsItemSelected(MenuItem item) {
     switch (item.getItemId()) {
        case R.id.action_save : 
           {
           //Write here what to do you on click
            return true;
         }
       }
      return super.onOptionsItemSelected(item);
     }
    

提交回复
热议问题