当前位置:操作系统 > 安卓/Android >>

Android常用代码记录

1.获得 RadioButton值

[java] 
rb1 = (RadioButton)findViewById(R.id.sex1); 
if (rb1.isChecked()) 

  sex = "M"; 
} else 

  sex = "F"; 


2.两个Activity间传递数据
[java] 
发送方: 
       
       Intent intent = new Intent(); 
       intent.setClass(EX03_11.this,EX03_11_1.class); 
       
       Bundle bundle = new Bundle(); 
       bundle.putDouble("height", height); 
       bundle.putString("sex", sex); 
       intent.putExtras(bundle); 
//打开另一个activity 
       startActivityForResult(intent, 0); 
接受方: 
    intent =this.getIntent(); 
    bundle=intent.getExtras(); 
    String sex =bundle.getString("sex"); 
    double height =bundle.getDouble("height"); 

3.打开一个消息框
[java] 
new AlertDialog.Builder(EX03_12.this) 
   .setTitle(R.string.app_about) 
   .setMessage(R.string.app_about_msg) 
   .setPositiveButton(R.string.str_ok, 
       newDialogInterface.OnClickListener() 
       { 
         publicvoid onClick(DialogInterface dialoginterface, int i) 
         { 
         }  www.zzzyk.com
       }).show(); 

4.改变文本框的字体
      mText.setTypeface(Typeface.createFromAsset(getAssets(),
          "fonts/HandmadeTypewriter.ttf"));
注: 在assets目录下建立fonts文件夹并放入HandmadeTypewriter.ttf字体文件

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,