为什么要用getBaseContext()方法代替this
来源:互联网 发布:投诉淘宝卖家有补偿吗 编辑:程序博客网 时间:2024/05/18 03:19
this
常常引用当前的 context。但是有些时候,必须使用getBaseContext()
来代替this
。就是说使用this
会引发错误。
如下面的例子:
Spinner spinner = (Spinner) findViewById(R.id.spinner);spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?>arg0, View arg1, int arg2, long arg3){ Toast.makeText(getBaseContext(),"SELECTED", Toast.LENGTH_SHORT).show(); //this line }
当我把getBaseContext()
变成this
就会有错误。
为什么这种情况下必须使用getBaseContext()
方法,而不能使用this
呢?
0 0
- 为什么要用getBaseContext()方法代替this
- 为什么要用getBaseContext()方法代替this
- Android:为什么要用getBaseContext()方法代替this?
- getApplicationContext()、Activity.this、 getBaseContext区别
- getApplicationContext()、getBaseContext()、this的区别
- getApplicationContext()、Activity.this、 getBaseContext区别
- getApplicationContext()、Activity.this、 getBaseContext区别
- getApplicationContext()、Activity.this、 getBaseContext区别
- getApplicationContext()、Activity.this、getBaseContext区别
- getApplicationContext()、Activity.this、 getBaseContext区别
- this、getBasecontext和getApplicationContext区别
- getApplicationContext()、getBaseContext()、this的区别
- getApplicationContext()、Activity.this、 getBaseContext区别
- 为什么要用foreach来代替for
- 为什么要用OSPF代替RIPv2
- getApplication()、getApplicationContext()、getBaseContext()、MainActivity.this、this
- 为什么用hexo代替jekyll
- getApplicationContext与Activity.this,getBaseContext的区别
- 提取特征的方法及不同场景的处理(目标跟踪)
- python函数 callable(object)
- 163.View the Exhibit and examine the description for the CUSTOMERS table.
- Html position(static | absolute | fixed | relative)定位
- Android View 如何测量
- 为什么要用getBaseContext()方法代替this
- <Head First Java>集合与泛型
- redis扫盲
- BZOJ 1812: [Ioi2005]riv
- 百度cookie使用分析
- Android studio用的几个插件
- 20160316 Codevs 1018 单词接龙,1166 矩阵取数(60'),1297 硬币,1009 产生数
- shiro 回话管理在spring中使用
- Android WebView加载网页,实现前进、后退、刷新、超链接