findViewById在片段中找不到ImageButton

时间:2018-08-16 18:32:44

标签: java android android-studio android-fragments imagebutton

我正在尝试为我正在创建的一个信息应用程序在一个片段中流式传输视频。当我创建图像按钮来控制视频时,use在行defmodule Events do @moduledoc false defmacro __using__(_) do quote do import unquote(__MODULE__), only: [defevent: 1, defevent: 2] Module.register_attribute(__MODULE__, :eventdoc, accumulate: true) end end defmacro defevent(module, fields \\ []) do keys = Keyword.keys(fields) quote do docs = Module.delete_attribute(__MODULE__, :eventdoc) defmodule unquote(module) do for doc <- docs do @moduledoc doc end @type t :: %__MODULE__{unquote_splicing(fields)} defstruct unquote(keys) end end end end 上给我一个“无法解析符号”错误,但是它可以在同一片段中找到视频视图。这是我的@doc中的findViewById方法:

btnPlayPause = (ImageButton)findViewById(R.id.play_pause_button);

这是我的包含VideoView和ImageButton的Fragment的XML:

onCreate

1 个答案:

答案 0 :(得分:1)

将活动类的标题更改为此:

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener

您忘记实现View.OnClickListener,因此onClick()方法不会覆盖任何内容