我正在学习Android。在创建构造函数时,我知道 this 关键字。但是,对于我来说,确切地知道这个在其他情况下所指的是非常困惑。
具体来说,在阅读代码示例时,在某些方法中,他们将 this 作为参数传递,我不知道这个意味着什么,所以我无法复制代码以后用。
请在阅读任何代码或将参数设为'this'时,告诉我应该怎样做以找出'this'的引用。
非常感谢!
请参阅此示例:
public class Example_5 extends AppCompatActivity {
ListView lv5;
List<Country> countries;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_5);
lv5 = (ListView) findViewById(R.id.lv5);
countries = new ArrayList<>();
countries.add(new Country("Vietnam", "Việt Nam", R.drawable.flag_vi));
countries.add(new Country("Laos", "Lào", R.drawable.flag_fr));
countries.add(new Country("Japan", "Nhật Bản", R.drawable.flag_jp));
countries.add(new Country("USA", "Mỹ", R.drawable.flag_us));
CountryAdapter3 adapter3 = new CountryAdapter3(this, countries, R.layout.item_layout_3);
lv5.setAdapter(adapter3);
}
}
答案 0 :(得分:0)
这样做:
Toast.makeText(this, this.getClass().toString(), Toast.LENGTH_SHORT).show();
您将看到班级名称