Android - LearnActivity
来源:互联网 发布:淘宝店怎么做百度推广 编辑:程序博客网 时间:2024/05/01 02:15
public class MainActivity extends Activity implements OnClickListener{Button btn_exit;Button btn_next;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); //调用父类的生命周期创建方法setContentView(R.layout.activity_main); //设置要使用的布局文件//requestWindowFeature(Window.FEATURE_NO_TITLE); //没有标题栏btn_exit = (Button) findViewById(R.id.btn_exit);btn_exit.setOnClickListener(this);btn_next = (Button) findViewById(R.id.btn_next);btn_next.setOnClickListener(this);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {//inflate(资源文件 , menu对象)getMenuInflater().inflate(R.menu.main, menu); return true; //true:允许该菜单显示}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {switch (item.getItemId()) {case R.id.add_item://提示信息Toast.makeText(MainActivity.this, "Add", Toast.LENGTH_LONG).show();break;case R.id.remove_item:Toast.makeText(MainActivity.this, "Remove", Toast.LENGTH_LONG).show();break;default:break;}return true;}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.btn_exit:finish(); //销毁本活动break;case R.id.btn_next://Intent用于组件间交互Intent intent = new Intent(MainActivity.this, SecondActivity.class); //定义一个意图startActivity(intent); //使用该意图break;default:break;}}}
public class SecondActivity extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); //调用父类的生命周期创建方法setContentView(R.layout.activity_second); //设置要使用的布局文件}}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/btn_exit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="退出" /> <Button android:id="@+id/btn_next" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转" /></LinearLayout>
activity_second.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这里是SecondActivity。" android:textSize="20sp" /></LinearLayout>
0 0
- Android - LearnActivity
- Android
- android
- Android
- android
- android
- Android
- Android
- android
- android
- android
- Android
- Android
- android!!!
- android
- android
- android
- android
- 并查集的实现
- 求两个有序数组的中位数
- java中的注解
- 分支预测
- Android 获取验证码后的倒计时功能
- Android - LearnActivity
- MVC,MVP 和 MVVM 的图示
- JSP中页面向Action传递参数的几种方式
- UVa 11732 strcmp函数 trie树 左儿子右兄弟表示法
- JS中的call()和apply()方法
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- JAVA学习20160229
- 浅拷贝造成的内存 被重复释放
- iOS中监控软键盘显示或隐藏的可靠方法