《第一行代码》读后感
2016-02-19 18:18
381 查看
1 AlertDialog 相关
AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("");
dialog.setMessage("");
dialog.setCancleable(false);
dialog.setPositiveButton("",new DialogInterface.OnClickListener(){
……);
dialog.setNegativeButton("",new DialogInterface.OnClickListener(){
……);
dialog.show();
2 搭建Web服务器
可参考:http://www.jb51.net/article/52086.htm
3 获取全局 Context
三步:
一 建立一个M有Application类继承Application
public class MyApplication extends Application{
private static Context context;
public void onCreate() {
context=getApplicationContext;
}
public static Context getContext() {
return context;
}
}
二 AndroidManifest.xml 初始化
<application
android:name="包名.MyAppliction">
三 直接调用
eg. Toast.makeText(MyAppliction.getContext(),"",Toast.LENGTH_SHORT).show();
4 Serializable 方式
序列化 让一个类实现Serializable 接口
Intent intent=new Intent();
intent.putExtra("banner_data",banner);
startActivity(intent);
另一个Activity 调用
Banner banner=(Banner)getIntent().getSerializableExtra("banner_data");
5 日志工具
AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("");
dialog.setMessage("");
dialog.setCancleable(false);
dialog.setPositiveButton("",new DialogInterface.OnClickListener(){
……);
dialog.setNegativeButton("",new DialogInterface.OnClickListener(){
……);
dialog.show();
2 搭建Web服务器
可参考:http://www.jb51.net/article/52086.htm
3 获取全局 Context
三步:
一 建立一个M有Application类继承Application
public class MyApplication extends Application{
private static Context context;
public void onCreate() {
context=getApplicationContext;
}
public static Context getContext() {
return context;
}
}
二 AndroidManifest.xml 初始化
<application
android:name="包名.MyAppliction">
三 直接调用
eg. Toast.makeText(MyAppliction.getContext(),"",Toast.LENGTH_SHORT).show();
4 Serializable 方式
序列化 让一个类实现Serializable 接口
public static class Banner implements Serializable { /** 图片id */ private String id; /** 图片地址 */ private String pic_path; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPic_path() { return pic_path; } public void setPic_path(String pic_path) { this.pic_path = pic_path; } }
Intent intent=new Intent();
intent.putExtra("banner_data",banner);
startActivity(intent);
另一个Activity 调用
Banner banner=(Banner)getIntent().getSerializableExtra("banner_data");
5 日志工具
public class LogUtil { public static final int VERBOSE=1; public static final int DEBUG=2; public static final int INFO=3; public static final int WARN=4; public static final int ERROR=5; public static final int NOTHING=6; public static final int LEVEL=VERBOSE; /** * 开发阶段 LEVEL=VERBOSE * 上线 LEVEL=NOTHING * */ public static void v(String tag,String msg){ if(LEVEL<=VERBOSE){Log.v(tag,msg);}} public static void d(String tag,String msg){ if(LEVEL<=DEBUG){Log.d(tag,msg);}} public static void i(String tag,String msg){ if(LEVEL<=INFO){Log.i(tag,msg);}} public static void w(String tag,String msg){ if(LEVEL<=WARN){Log.w(tag,msg);}} public static void e(String tag,String msg){ if(LEVEL<=ERROR){Log.e(tag,msg);} } }
相关文章推荐
- Android编程之自定义AlertDialog(退出提示框)用法实例
- Android使用自定义alertdialog实现确认退出按钮
- Android中AlertDialog用法实例分析
- Android修改源码解决Alertdialog触摸对话框边缘消失的问题
- Android实现点击AlertDialog上按钮时不关闭对话框的方法
- 简析Android多种AlertDialog对话框效果
- Android入门之AlertDialog用法实例分析
- Android入门-AlertDialog
- Android学习笔记-Lesson 4: Favorite Twitter Searches Ap
- 为自定义的ListView的条目添加对话框
- 7中android常用的提示框(AlertDialog)
- android有时候需要show对话框,但是对话框需要依附于activity,如果没有activity怎么办
- android中在广播中弹出pop框的局限性
- AlertDialog类的使用
- Java常用日志工具
- AlertDialog中EditText输入法调不出 edittext调用输入法等问题
- AlertDialog 修改内部元素属性 按钮 message title
- android AlertDialog自定义布局文件
- Android 对话框
- android————AlertDialog,ProGressDialog