Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正面临这个问题,我想找到将它传递给按钮和 setOnClickListener 的原因。
上下文是有关应用程序环境的全局信息的接口。这是一个抽象类,其实现由Android系统提供。它允许访问特定于应用程序的资源和类,以及向上调用应用程序级操作,例如启动活动、广播和接收意图等。
按钮也是应用程序的资源,所以如果你想创建按钮或任何小部件,那么你必须在小部件的构造函数中传递上下文。
了解更多详情