杂乱的小知识——Android学习笔记
1.
继承Service,intent传到Service的时候就会调用Service中的函数
public int onStartCommand(Intent intent, int flags, int startId) { return super.onStartCommand(intent, flags, startId); }
这里的Intent对象传过来,不需要再在用
Intent intent = getIntent();
mp3Info = (Mp3Info) intent.getSerializableExtra("mp3Info");
获取,这里可以直接用mp3Info = (Mp3Info) intent.getSerializableExtra("mp3Info");即可。相当于Intent intent = getIntent();已经给你写好了。
2.
Inflater英文意思是膨胀,在Android中应该是扩展的意思吧。
LayoutInflater的作用类似于 findViewById(),不同点是LayoutInflater是用来找layout文件夹下的xml布局文件,并且实例化!而 findViewById()是找具体某一个xml下的具体 widget控件(如:Button,TextView等)。
LayoutInflater的作用类似于 findViewById(),不同点是LayoutInflater是用来找layout文件夹下的xml布局文件,并且实例化!而 findViewById()是找具体某一个xml下的具体 widget控件(如:Button,TextView等)。
LayoutInflater li = LayoutInflater.from(AddNew.this);
//找到layout文件下的imageswitch
View imageChooseView = li.inflate(R.layout.imageswitch, null); //通过渲染xml文件,得到一个视图(View),再拿到这个View里面的Gallery gallery = (Gallery)imageChooseView.findViewById(R.id.gallery);
3.
AlertDialog的使用
1 public void initImageChooseDialog() { 2 if(imageChooseDialog == null) { 3 AlertDialog.Builder builder = new AlertDialog.Builder(this); 4 builder.setTitle("请选择图像") 5 .setView(imageChooseView).setPositiveButton("确定", new DialogInterface.OnClickListener() { 6 public void onClick(DialogInterface dialog, int which) { 7 imageChanged = true; 8 previousImagePosition = currentImagePosition; 9 imageButton.setImageResource(images[currentImagePosition%images.length]); 10 } 11 }) 12 .setNegativeButton("取消", new DialogInterface.OnClickListener() { 13 public void onClick(DialogInterface dialog, int which) { 14 currentImagePosition = previousImagePosition; 15 } 16 }); 17 imageChooseDialog = builder.create(); 18 } 19 }
4 TimePicker 取时间是用下面的方法
1 Calendar c = Calendar.getInstance(); 2 int hour = c.get(Calendar.HOUR); 3 int min = c.get(Calendar.MINUTE);
5 Builder 设置多选对话框
1 AlertDialog.Builder builderWeek = new AlertDialog.Builder( 2 MainActivity.this) 3 .setTitle("重复闹钟设置") 4 .setMultiChoiceItems( 5 new String[] { "星期一", "星期二", "星期三", "星期四", 6 "星期五", "星期六", "星期日"},new boolean[] { false, false, false, false, 7 false, false, false }, 8 new OnMultiChoiceClickListener() { 9 public void onClick(DialogInterface dialog, 10 int which, boolean isChecked) { 11 checked[which] = isChecked; 12 13 } 14 }).......
6打电话 发短信
Intent intent = new Intent(); intent.setAction("android.intent.action.CALL"); intent.setData(Uri.parse("tel:"+ number)); startActivity(intent);//方法内部会自动为Intent添加类别:android.intent.category.DEFAULT,并在androidmanifest中申明变量。
1 SmsManager manager = SmsManager.getDefault(); 2 ArrayList<String> texts = manager.divideMessage(content); 3 for(String text : texts){ 4 manager.sendTextMessage(number, null, text, null, null); 5 } 6 Toast.makeText(MainActivity.this, R.string.success, Toast.LENGTH_LONG).show(); 7 }
posted on 2012-10-15 09:36 liyajun2012 阅读(141) 评论(0) 编辑 收藏 举报