什么意思了"这"背景? [英] What's meant by the "this" context?
问题描述
我已经看过了很多的android教程在互联网上。在这些教程中,他们使用了这
上下文语境无处不在。我知道这
关键字意味着在Java中,但我不能让这种平等,在Android上这
关键词编程。例如,在 AlertDialog.Builder
,在developer.android.com现场,只有一个在参数上下文的参考,但我无法了解这是什么这
这里的意思。
I have looked at a lot of android tutorials over the internet. In these tutorials they use the this
context for the context everywhere. I know what this
keyword means in Java, but I can't make equal this, with the this
keyword in Android programming. For example, at AlertDialog.Builder
, on the developer.android.com site, there is only one reference at the parameters to the Context, but I can't learn what this this
means here.
推荐答案
如果你有一个活动,您可以使用这
,因为:
if you have an Activity you can use this
because:
-
这
是一个类 的当前实例
- 在一个活动是从类上下文继承
this
is the current instance of a class- an Activity is inherits from the class "Context"
所以你可以使用你当前活动的上下文。
so you can use your current Activity as a Context.
看这里的Acitivty文档: <一href="http://developer.android.com/reference/android/app/Activity.html">http://developer.android.com/reference/android/app/Activity.html
Look here for the Acitivty doc: http://developer.android.com/reference/android/app/Activity.html
和这里的解释这
:
<一href="http://download.oracle.com/javase/tutorial/java/javaOO/thiskey.html">http://download.oracle.com/javase/tutorial/java/javaOO/thiskey.html
这篇关于什么意思了&QUOT;这&QUOT;背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!