我已经看过了很多的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文档: http://developer.android.com/reference/android/app/Activity.html
Look here for the Acitivty doc: http://developer.android.com/reference/android/app/Activity.html
和这里的解释这
:
http://download.oracle.com/javase/tutorial/java/javaOO/thiskey.html