开始读《Android移动开发入门进阶》书的学习小结。

1 <Button android:text="@+id/Button01">
当新的一个button时,必须要@告诉XML解析器,解析ID字符后的部分,
当引用一个android id时,就不需要+号了,直接这样:
android:id="@android:id/Button01

代码中去获得一个button:
Button mybutton=(Button)findViewById(R.id.my_button);

2 TABLELAYOUT的例子:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:stretchColumns="1">

<TableRow>
<TextView android:text="用户名:" android:textStyle="bold"
android:gravity="right" android:padding="3dip" />

<EditText android:id="@+id/username" android:padding="3dip"
android:scrollHorizontally="true" />
</TableRow>

<TableRow>
<TextView android:text="登录密码:" android:textStyle="bold"
android:gravity="right" android:padding="3dip" />

<EditText android:id="@+id/password" android:password="true"
android:padding="3dip" android:scrollHorizontally="true" />
</TableRow>

<TableRow android:gravity="right">

<Button android:id="@+id/cancel"
android:text="取消" />

<Button android:id="@+id/login"
android:text="登录" />
</TableRow>
</TableLayout>
3 relative_layout的例子
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/blue" android:padding="10dip">

<TextView android:id="@+id/label" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="请输入用户名:" />

<!--
这个EditText放置在上边id为label的TextView的下边
-->
<EditText android:id="@+id/entry" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label" />

<!--
取消按钮和容器的右边齐平,并且设置左边的边距为10dip
-->
<Button android:id="@+id/cancel" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip" android:text="取消" />

<!--
确定按钮在取消按钮的左侧,并且和取消按钮的高度齐平
-->
<Button android:id="@+id/ok" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/cancel"
android:layout_alignTop="@id/cancel" android:text="确定" />


</RelativeLayout>


4 处理用户的点击事件,这个简单
button0 = (Button) findViewById(R.id.button0);
button0.setOnClickListener(listener0);
listener0 = new OnClickListener() {
public void onClick(View v) {
Intent intent0 = new Intent(ActivityMain.this, ActivityFrameLayout.class);
setTitle("FrameLayout");
startActivity(intent0);
}
};

5 访问res/drawable目录下名叫a1的图片资源
Drawable d=this.getResources().getDrawable(R.drawable.a1);


6 MENU的操作
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, ITEM0, 0, "显示button1");
menu.add(0, ITEM1, 0, "显示button2");
menu.findItem(ITEM1);
return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case ITEM0:
actionClickMenuItem1();
break;
case ITEM1:
actionClickMenuItem2(); break;

}
return super.onOptionsItemSelected(item);}


7 取得前一个ACTIVETY传过来的值的方法:
Intent intent = getIntent();
String name = (String) intent.getExtras().get("name");
比如在一个文本框中输入了值NAME,点BUTTON1弹出一个对话框,把NAME值传过去,这时可以这样:
btn_dialog.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//通过Intent传递参数
Intent intent = new Intent();
intent.putExtra("name", editText.getText().toString());
//启动另一个Activity
intent.setClass(MultiActivity.this, AlertDialog.class);
startActivity(intent);
}
});
用putExtra放参数的值,用startActivety启动一个新的activety

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jackyrongvip/archive/2010/01/15/5195687.aspx

更多相关文章

  1. Android官方入门文档[6]添加Action按钮
  2. [置顶] Android学习进阶路线导航线路(Android源码分享)
  3. Android高手进阶教程(十七)之---Android中Intent传递对象的两种
  4. android常用UI控件的使用例子
  5. 【Android 进阶】Android Home 键监听
  6. Android高手进阶教程(三)之----Android 中自定义View的应用
  7. 界面编程之基本界面组件(5)ToggleButton(状态开关按钮)
  8. [Android Pro] 完美Android Cursor使用例子(Android数据库操作)
  9. 如何导入android中的sample例子到eclipse中

随机推荐

  1. 解决Your content must have a ListView
  2. 初学者之Android HelloWorld项目
  3. Android之Intent详解
  4. Android各个版本命名(从1.5到6.0)
  5. Android 利用JNI实现串口通信
  6. 史上最详细的Android Studio系列教程三--
  7. Android的UI学习
  8. 在Android实现人脸识别的详细过程
  9. Android的AIDL以及挂断电话
  10. 如何在android平台上实现语音识别