android this的用法~麻烦跟我解释一下这里面的几个this~
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/06 21:33:44
android this的用法~麻烦跟我解释一下这里面的几个this~
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License,Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing,software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.apis.view;
import com.example.android.apis.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;
/**
* Uses a TextSwitcher.
*/
public class TextSwitcher1 extends Activity implements ViewSwitcher.ViewFactory,
View.OnClickListener {
private TextSwitcher mSwitcher;
private int mCounter = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text_switcher_1);
mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(out);
Button nextButton = (Button) findViewById(R.id.next);
nextButton.setOnClickListener(this);
updateCounter();
}
public void onClick(View v) {
mCounter++;
updateCounter();
}
private void updateCounter() {
mSwitcher.setText(String.valueOf(mCounter));
}
public View makeView() {
TextView t = new TextView(this);
t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
t.setTextSize(36);
return t;
}
}
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License,Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing,software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.apis.view;
import com.example.android.apis.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;
/**
* Uses a TextSwitcher.
*/
public class TextSwitcher1 extends Activity implements ViewSwitcher.ViewFactory,
View.OnClickListener {
private TextSwitcher mSwitcher;
private int mCounter = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text_switcher_1);
mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(out);
Button nextButton = (Button) findViewById(R.id.next);
nextButton.setOnClickListener(this);
updateCounter();
}
public void onClick(View v) {
mCounter++;
updateCounter();
}
private void updateCounter() {
mSwitcher.setText(String.valueOf(mCounter));
}
public View makeView() {
TextView t = new TextView(this);
t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
t.setTextSize(36);
return t;
}
}
this 当前类(activity等)其指向是当前的.
比如程序中的nextButton.setOnClickListener(this);
这个this 就相当当前类的Context,即为,当期
如下,
nextButton.setOnClickListener(new OnClickListener() {
\x05\x05
\x05\x05@Override
\x05\x05public void onClick(View v) {
Toast.makeText(TextSwitcher1.this,"看这里",5000).show();
\x05\x05\x05}
在这个里面Toast(context,string,time),中,你直接写this 会出错的,因为你当前 的类是OnClickListener类.而不失我们的Activity 类,这样你写上去的会出现错误的!所以在内部类中你写this,指的是内部类,而不是外部的!this 就是当前,TextSwitcher1.this后面能调出TextSwitcher1的所有属性!
另外咱们在调用一些方法,传的Context 就是把当前类 传过去使用.
\x05\x05\x05
\x05\x05}
\x05};)
比如程序中的nextButton.setOnClickListener(this);
这个this 就相当当前类的Context,即为,当期
如下,
nextButton.setOnClickListener(new OnClickListener() {
\x05\x05
\x05\x05@Override
\x05\x05public void onClick(View v) {
Toast.makeText(TextSwitcher1.this,"看这里",5000).show();
\x05\x05\x05}
在这个里面Toast(context,string,time),中,你直接写this 会出错的,因为你当前 的类是OnClickListener类.而不失我们的Activity 类,这样你写上去的会出现错误的!所以在内部类中你写this,指的是内部类,而不是外部的!this 就是当前,TextSwitcher1.this后面能调出TextSwitcher1的所有属性!
另外咱们在调用一些方法,传的Context 就是把当前类 传过去使用.
\x05\x05\x05
\x05\x05}
\x05};)
android this的用法~麻烦跟我解释一下这里面的几个this~
this 在这里的用法
翻译:by this time next year ,并解释一下by在这里的用法
Android中this.*与*.this还有*.class的区别是什么?
解释一下这里over的用法
谁能帮我解释一下这里面这些属性的含义?
java一句非常简单的this语句,只是想要详细解释一下这个this用法.
My plan is to make this "dynamic",这个is to 是什么用法 谁可以跟我解释一下这句语
this指针的用法
Is this的用法
谁能解释一下这里of的用法?
举几个例子说明C#中的this关键字的用法