背景VS意见 [英] context vs views

查看:94
本文介绍了背景VS意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释的内容和观点之间的差异,然后我们什么时候去的上下文或查看?在大多数的程序,我觉得无论是上下文或视图被传递到某些方法,什么是传球方面还是以方法的实际需要?

can anyone explain the difference between context and views and when do we go for context or view ? In most of the program I find either context or view being passed to certain methods , what is actual need of passing context or view to methods?

推荐答案

这是一个奇怪的问题。视图描述你的用户界面的一个组成部分。它可以有onClickListeners,属性等。但是,每一个观点在某些情况下创建的,通常活动的环境。

This is a strange question. View describes one element of your ui. It can have onClickListeners, properties and so on. But every view is created in some context, usually Activity's context.

上下文作为本身就是像你code在执行环境,它可以访问用户界面(如果它是一个活动),它可以包含一些全局数据(应用程序上下文),并已获得资源(所有的上下文)。此外,上下文允许您执行常见的Andr​​oid操作,如广播意图,启动活动和服务。

Context as itself is something like environment your code is executed in. It has access to ui(if it is an activity), it can contain some global data(application context), and has access to the resources(all of the contexts). Also, context allows you to perform common android operations like broadcasting intents, start activities and services.

所以,意见应当你想要做一些与特定视图通过。 上下文传递,当你需要访问的资源,全球数据或UI的背景下,或启动其他Android组件。

So, views should be passed when you want to do something with a particular view. Context is passed when you need access to resources, global data or ui context, or launch other android components.

这篇关于背景VS意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆