`
童梦新苑
  • 浏览: 40194 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

android Intent和菜单的使用

阅读更多

首先我们需要知道Intent这个东西是用来干什么的:

   intent主要可以看着是一个能够在两个Activity之间传输数据的这么一个对象,那么他的具体用法怎么用啊

我们下来就来看看这个例子吧:

package demo.jsj;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Activity03 extends Activity {
    private EditText factorOne;
    private EditText factorTwo;
    private TextView symbol;
    private Button calculate;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //根据控件的Id取得控件的对象(通过布局文件进行获取)
        factorOne = (EditText)this.findViewById(R.id.factorOne);
        factorTwo = (EditText)this.findViewById(R.id.factorTwo);
        symbol = (TextView)this.findViewById(R.id.symbol);
        calculate = (Button)findViewById(R.id.calculate);
        symbol.setText(R.string.symbol);
        calculate.setText(R.string.caloulate);
        calculate.setOnClickListener(new ClaculateListener());
    }
    
    //添加菜单
    
    
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
    	menu.add(0,1,1,R.string.out);//第二个参数为ID
    	menu.add(0,2,2,R.string.about);
		return super.onCreateOptionsMenu(menu);
	}
    //设置菜单的操作
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if(item.getItemId() == 1){
			finish();
		}
		return super.onOptionsItemSelected(item);
	}

	class ClaculateListener implements OnClickListener{

		@Override
		public void onClick(View v) {
			//取得两个控件的值
			String factorOneStr = factorOne.getText().toString();
			String factorTwoStr = factorTwo.getText().toString();
			Intent intent = new Intent();
			intent.putExtra("one", factorOneStr);
			intent.putExtra("two", factorTwoStr);
			intent.setClass(Activity03.this, ResultActivity.class);
			Activity03.this.startActivity(intent);
		}
    	
    }
}

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    
<EditText
	android:id="@+id/factorOne"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	/>
<TextView  
	android:id="@+id/symbol"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<EditText
	android:id="@+id/factorTwo"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	/>
<Button
	android:id="@+id/calculate"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	/>
</LinearLayout>

 

  • 大小: 20 KB
分享到:
评论

相关推荐

    Android activity、菜单及dialog、列表等常见UI源码.rar

    Android activity、菜单及dialog、列表等常见UI源码,下面依次介绍各目录里的功能演示:  activity_intent:activity的跳转1.不带返回值的跳转2.带返回值的跳转,intent的简单介绍。Bundle的简单介绍。  dialog...

    android基础总结篇之九:Intent应用详解

    主要介绍了android基础总结篇之九:Intent应用详解,有需要的可以了解一下。

    《Android高级编程》

    4.5 创建和使用菜单 4.5.1 Android菜单系统简介 4.5.2 定义活动的菜单 4.5.3 动态更新菜单项 4.5.4 处理菜单选择 4.5.5 子菜单和上下文菜单 4.5.6 To-Do List示例续 4.6 小结 第5章 Intent、广播接收器、 Adapter和...

    Android高级编程--源代码

    作为使用androidsdk构建这些应用程序的实用指南书籍,《android高级编程》从始至终穿插了一系列示例项目,每个项目都引入android的新功能和新技术,以助您达到最圆满的学习效果。书中介绍android的所有基本功能,并...

    Android入门到精通源代码.

    第6章 Android菜单和布局设计 6.1 菜单(Menu) 6.1.1 上下文菜单(ContextMenu) 6.1.2 选项菜单(OptionsMenu) 6.1.3 基于XML的菜单结构 6.2 界面布局设计 6.2.1 基于XML的布局设计 6.2.2 线性布局(LinearLayout...

    精通ANDROID 3(中文版)1/2

    1.5 使用Android SDK开发最终用户应用程序  1.5.1 Android模拟器  1.5.2 Android UI  1.5.3 Android基础组件  1.5.4 高级UI概念  1.5.5 Android Service组件  1.5.6 Android媒体和电话组件  1.5.7 ...

    Android实现菜单关联activity的方法示例

    主要介绍了Android实现菜单关联activity的方法,涉及Android使用Intent实现菜单关联activity相关操作技巧,需要的朋友可以参考下

    Android学习教程之圆形Menu菜单制作方法(1)

    本文实例为大家分享了Android圆形菜单的使用方法,供大家参考,具体内容如下 MainActivity.java代码: package siso.handlerdemo; import android.app.NotificationManager; import android.content.Intent; import ...

    Android高级编程.pdf

    5.1.3 使用Intent Filter作为插件和扩展 5.1.4 使用Intent来广播事件 5.2 Adapter简介 5.2.1 Android提供的部分Adapter简介 5.2.2 使用Adapter绑定数据 5.3 使用Internet资源 5.3.1 连接到Internet资源 5.3.2 利用...

    疯狂Android讲义源码

     第5章 使用Intent和IntentFilter  第5章 进行通信 196  5.1 Intent对象详解 197  5.1.1 使用Intent启动系统组件 197  5.2 Intent的属性及intent-filter  配置 198  5.2.1 Component属性 198  5.2.2 Action...

    Android高级编程 part1

    作为使用AndroidSDK构建这些应用程序的实用指南书籍,《Android高级编程》从始至终穿插了一系列示例项目,每个项目都引入Android的新功能和新技术,以助您达到最圆满的学习效果。书中介绍Android的所有基本功能,并...

    Android高级编程 part2

    作为使用AndroidSDK构建这些应用程序的实用指南书籍,《Android高级编程》从始至终穿插了一系列示例项目,每个项目都引入Android的新功能和新技术,以助您达到最圆满的学习效果。书中介绍Android的所有基本功能,并...

    Android利用Intent实现记事本功能(NotePad)

    本文实例为大家分享了Intent如何实现一个简单的记事本功能的演示过程,供大家参考,具体内容如下 1、运行截图 单击右上角【…】会弹出【添加】菜单项,长按某条记录会弹出快捷菜单【删除】项。 2、主要设计步骤 (1...

    Android UI组件实例集合

    是 Android 上实现类似 Facebook 和 Path 2.0 滑动式菜单的组件。 12、AsyncImageView 是 Android 上的一个异步从网络上获取图片并进行浏览的开源组件,可自动在本地进行缓存。该项目是 GreenDroid 的一部分。 13...

    android开发使用例子

    要使用这个必须在配置文件中加入&lt;uses-permission id="Android.permission.CALL_PHONE" /&gt; 发送SMS/MMS 调用发送短信的程序 1. Intent it = new Intent(Intent.ACTION_VIEW); 2. it.putExtra("sms_body", "The ...

    Android编程入门很简单.(清华出版.王勇).part1

    8.1.1使用Intent连接Activity 8.1.2 Activity的生命周期 …… 第9章Android中的数据存储 第10章绚丽的多媒体技术 第11章Android网上冲浪 第12章Android地图服务 第4篇项目案例开发 第13章联系人助手 第14章个人轨迹...

    android一步一步最基础学习__新手

    第十六讲:菜单 Android Menu 第十七讲:对话框 Android Dialog 第十八讲:Android SharedPreferences和File 第十九讲:Android Notification的使用入门 第二十讲:Content Provider 使用入门 第二十一讲...

    《Google Android开发入门与实战》

    第7章 良好的学习开端——Android基本组件介绍之Android应用的灵魂——Intent和Activity介绍与实例 第7章 良好的学习开端——Android基本组件介绍之用好列表,做好程序——列表(ListView)介绍与实例 第7章 良好的...

Global site tag (gtag.js) - Google Analytics