IDEA的笔记(L2 )
来源:互联网 发布:简易衣柜 知乎 编辑:程序博客网 时间:2024/06/07 16:18
IDEA的笔记L2
知识总结
android:textAllCaps="true" 变量作用域 : Variable scope
个人觉得视频里的布局太丑了,所有自己改了下:
MainActivity代码
/** * This app displays an order form to order coffee. */ public class MainActivity extends ActionBarActivity { private int quantity = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.myjustjava); } public void increment(View view) { quantity = quantity + 1; display(quantity); } public void decrement(View view) { quantity = quantity - 1; display(quantity); } /** * This method is called when the order button is clicked. */ public void submitOrder(View view) { display(quantity); displayPrice(quantity * 5); } /** * This method displays the given quantity value on the screen. */ private void display(int number) { TextView quantityTextView = (TextView) findViewById( R.id.quantity_text_view); quantityTextView.setText("" + number); } // @TargetApi(Build.VERSION_CODES.N) // private void displayPrice(int number){ // TextView priceTextView = (TextView) findViewById(R.id.price_text_view); // priceTextView.setText(NumberFormat.getCurrencyInstance().format(number)); @TargetApi(Build.VERSION_CODES.N) private void displayPrice(int number) { TextView priceTextView = (TextView) findViewById(R.id.price_text_view); priceTextView.setText(NumberFormat.getCurrencyInstance().format(number)); }}
@SuppressLint(“NewApi”)和@TargetApi()的区别
在Android代码中,我们有时会使用比我们在AndroidManifest中设置的android:minSdkVersion版本更高的方法,此时编译器会提示警告,解决方法是在方法上加上@SuppressLint(“NewApi”)或者@TargetApi()。
那他们之间有什么区别呢,很简单,
@SuppressLint(“NewApi”)屏蔽一切新api中才能使用的方法报的android lint错误
@TargetApi() 只屏蔽某一新api中才能使用的方法报的android lint错误
举个例子,某个方法中使用了api9新加入的方法,而项目设置的android:minSdkVersion=8,此时在方法上加@SuppressLint(“NewApi”)和@TargetApi(Build.VERSION_CODES.GINGERBREAD)都可以,以上是通用的情况。
而当你在此方法中又引用了一个api11才加入的方法时,@TargetApi(Build.VERSION_CODES.GINGERBREAD)注解的方法又报错了,而@SuppressLint(“NewApi”)不会报错,这就是区别。
当然,不管你使用了哪个注解,作用仅仅是屏蔽android lint错误,所以在方法中还要判断版本做不同的操作,比如:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { // some code} else {// Pre GINGERBREAD // some code}
java转义字符表
阅读全文
0 0
- IDEA的笔记(L2 )
- 【笔记】机器学习里的各种LOSS(L1,L2)
- IDEA的笔记(L1 )
- IDEA的笔记(L3)
- IDEA的笔记(L4)
- IDEA的笔记(1A )
- PowerPC60x系列的L2 cache相关资料阅读笔记
- dropout和L1,L2正则化的理解笔记
- 机器学习笔记(二)L1,L2正则化
- Intellij IDEA的使用笔记
- 笔记-L1、L2范数理解
- 二级缓存(L2 CACHE)
- L2
- L2
- OpenStack Neutron DVR L2 Agent的初步解析 (一)
- OpenStack Neutron DVR L2 Agent的初步解析(二)
- PAT-4C-L2-006-树的遍历(DFS)
- PAT L2-012. 关于堆的判断(堆)
- 用Python学《微积分B》(Chapter 4-3 Special Derivate)
- RESTful API 设计指南
- PAT All Roads Lead to Rome 单源最短路
- Springmvc几种页面跳转方式
- python 控制台同一位置输出
- IDEA的笔记(L2 )
- R语言小波转换
- POJ 1789 Truck History(最小生成树,prim算法)
- 去掉vue.js中的Eslint
- 左旋转字符串
- Quartz conTrigger 定时器表达式大全
- OSI七层模型和TCP/IP四层模型的概念
- 【读书笔记】TCP/IP 网络编程 第23章 IOCP模型
- 厘清几个概念:互联网/WWW/Web 、URI/URL、主机名/域名