android(29)(显示意图与隐式意图,byte转换成int类型需注意的地方)
来源:互联网 发布:2017时尚行业数据报告 编辑:程序博客网 时间:2024/06/07 20:45
1.布局文件一:<RelativeLayout 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" tools:context=".MainActivity" > <Button android:id="@+id/bt_calc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:onClick="enter" android:text="点击进入人品计算器" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:src="@drawable/rp" /> <EditText android:id="@+id/et_name" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/bt_calc" android:hint="请输入要计算的姓名" /></RelativeLayout>2.布局文件二:<RelativeLayout 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" tools:context=".CalcActivity" > <TextView android:id="@+id/tv_result" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="我是计算器页面" /></RelativeLayout>3.业务逻辑代码实现:public class MainActivity extends Activity { private EditText et_name; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et_name = (EditText) findViewById(R.id.et_name); } //显式意图 :必须指定要激活的组件的完整包名和类名 (应用程序之间耦合在一起) // 一般激活自己应用的组件的时候 采用显示意图 //隐式意图: 只需要指定要动作和数据就可以 ( 好处应用程序之间没有耦合) //激活别人写的应用 隐式意图, 不需要关心对方的包名和类名 public void enter(View view){ String name = et_name.getText().toString().trim(); if(TextUtils.isEmpty(name)){ Toast.makeText(this, "请输入姓名", 0).show(); return; } //意图 开电视 打人 打酱油 Intent intent = new Intent(this, CalcActivity.class); intent.putExtra("name", name); //显式意图 //intent.setClassName(getPackageName(), "com.itheima.rpcalc.CalcActivity");//不指定动作,也不指定数据 直接指定要激活的组件 startActivity(intent); //隐式意图 //intent.setAction(action); //intent.setData(data); }计算的代码:public class CalcActivity extends Activity { private TextView tv_result; //当activity被创建的时候调用的方法 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calc); tv_result = (TextView) findViewById(R.id.tv_result); Intent intent = getIntent(); String name = intent.getStringExtra("name"); byte[] result = name.getBytes(); int number = 0; for(byte b :result){ number += b&0xff;//byte类型转换为int类型 } int sorce = Math.abs(number)%100; tv_result.setText(name+"的人品:"+sorce); }
0 0
- android(29)(显示意图与隐式意图,byte转换成int类型需注意的地方)
- (Android review)显示意图激活与隐式意图激活
- Android之显示意图与隐式意图
- Android学习记录(7)—Intent中显示意图和隐式意图的用法
- Android 隐式意图和显示意图
- Android 隐式意图和显示意图
- Android 显示意图和隐式意图的区别
- Android 显示意图和隐式意图的区别
- Android之显示意图与隐式意图的使用场景
- Android Intent中显示意图与隐式意图的基本用法
- android Intent (隐式意图和显示意图)
- android intent 隐式意图和显示意图(activity跳转)
- android intent 隐式意图和显示意图(activity跳转)
- android Intent (隐式意图和显示意图)
- Android中显示意图和隐式意图
- Intent中显示意图和隐式意图的用法
- 显示意图和隐式意图的使用场景
- Intent中显示意图和隐式意图的用法
- 【thinkphp3.x】thinkphp3.x中C方法获取或设置配置参数的值
- 未将对象引用设置到对象的实例--可能出现的问题总结
- 满减优惠用多了,想过怎么运作的吗?
- [JSP]EL表达式语言
- 黑马程序员——C基础之自增自减运算符
- android(29)(显示意图与隐式意图,byte转换成int类型需注意的地方)
- localstorage 必知必会
- 库函数记录-findwindow
- LeetCode -Longest Common Prefix
- 详解Java GC的工作原理+Minor GC、FullGC
- struts2之单个文件上传
- 【maven】pom.xml详解
- 工厂模式:封装对象的创建(一、在基类中定义一个静态成员函数)
- 黑马程序员——C基础之sizeof运算符