zoukankan      html  css  js  c++  java
  • Fragment 代码怎么写

    public class Voice extends Fragment implements OnClickListener {
     
    
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState) {
                // TODO Auto-generated method stub
             System.out.println("ExampleFragment--onCreateView");
                View view = inflater.inflate(R.layout.voice, container, false);
                
                 view.findViewById(R.id.button1).setOnClickListener(this);
                   view.findViewById(R.id.button2).setOnClickListener(this);
                
                   return view;
                     
         }
         
         //http://www.cnblogs.com/xiaobo-Linux/
         
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
          
         //     initLayout();
             System.out.println("oncreate");
        }  
    
         
    
         
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
            case R.id.button1:
             
           getActivity().startService(new Intent(getActivity(),VoiceService.class));     
                break;
             
            case R.id.button2:
           
           getActivity().stopService(new Intent(getActivity(),VoiceService.class));        
          
                break;
         
            default:
                break;
            }
        }
    
        
    public void onPause()
    {
         super.onPause();
         System.out.println("ExampleFragment--onPause");
         
    }
    
         
        
    }

    在 oncreateView 里面 进行页面初始化

    view view.findViewById

    this 改成 getActivity()

  • 相关阅读:
    kibana 版本kibana-4.3.1 修改地图
    安装GeoIP数据库
    获取nginx ip地理信息
    数据接口示例
    elasticsearch 搜索不支持单词的部分进行匹配
    5,扩展方案
    (?m)使用实例
    Oracle 唯一主键引发的行锁
    场景2 nginx 错误日志格式:
    POSTGRESQL NO TABLE
  • 原文地址:https://www.cnblogs.com/zhaocundang/p/5451009.html
Copyright © 2011-2022 走看看