zoukankan      html  css  js  c++  java
  • [Android]新版的sdk中新建一个android应用,增加的PlaceholderFragment这个静态类发生的事情

    1,首先发生的是有两个布局xml,一个activity_main.xml,一个是fragment_main.xml一开始没在意,后来仔细看了原来是新功能的fragment概念等于多个场景在这个activity中切换,

    按照原来的理念就是

     1 @Override
     2     protected void onCreate(Bundle savedInstanceState) {
     3         super.onCreate(savedInstanceState);
     4         setContentView(R.layout.activity_main);
     5 
     6         latitudetext = (TextView) findViewById(R.id.latitudetext);
     7         longtitudetext = (TextView) findViewById(R.id.longtitudetext);
     8         altitudetext = (TextView) findViewById(R.id.altitudetext);
     9         speedtext = (TextView) findViewById(R.id.speedtext);
    10         button1 = (Button) findViewById(R.id.button1);
    11         buttonlisten mybuttonlisten = new buttonlisten();
    12         button1.setOnClickListener(mybuttonlisten);//错误在这里
    13         if (savedInstanceState == null) {
    14             getSupportFragmentManager().beginTransaction()
    15                     .add(R.id.container, new PlaceholderFragment()).commit();
    16         }
    17 
    18     }

    在原本的activity中添加这些对xml控件操作的一些代码,后来发现运行时候报错,错误在12行。

    仔细搜索了一下,各种百度一下,发现是因为我这些控件都是在fragment的xml中,原本的activity直接就加入了fragment的xml场景,等于默认的activity_main.xml并没有运作,直接加载了另一个xml,而我把控件代码依旧放在setcontenview后面,意味着并不能在activity中找到这些控件,所以绑定监听器的操作不能执行,我应该把控件代码放到fragment的create的方法中去。

  • 相关阅读:
    while循环和递归
    ASP.NET Core Swagger 显示接口注释
    ABP依赖注入
    EF Core 笔记
    .NET Core 管道过滤器扩展
    ABP权限认证
    552 you must authentication
    C# 多线程写文件,时常写不成功
    .Net 的一些插件
    多线程下HttpContext.Current 的问题
  • 原文地址:https://www.cnblogs.com/zoe-j/p/3754122.html
Copyright © 2011-2022 走看看