由于才学,这个布局实在不敢恭维,请各位谅解!!
好吧,废话不多说了,来看看这个代码吧(关于这个例子本人会在后面继续添加,不断增加)!!
其中使用到得技术有:intent Bundle AlertDialog SMS Activity
首先是程序的布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0,1,2"
android:shrinkColumns="0,1,2"
>
<TextView
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<!--//添加两个输入框(使用TabLayout进行布局) -->
<TableLayout
android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@id/hello"
>
<TableRow>
<EditText
android:id="@+id/one"
android:gravity="left"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/hello"/>
<TextView
android:id="@+id/fangfa"
android:gravity="left"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="X"/>
<EditText
android:id="@+id/two"
android:gravity="left"
android:layout_column="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/one"/>
</TableRow>
<TableRow android:stretchColumns="">
<Button
android:id="@+id/cacl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/table"
android:layout_alignParentLeft="true"
android:text="@string/caleValue" />
<Button
android:id="@+id/smstoId"
android:layout_column="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/table"
android:layout_alignRight="@id/cacl"
android:text="@string/smstoValue"/>
</TableRow>
</TableLayout>
<!--添加两个控件分别启动两个应用(短信应用 计算器Demo)-->
</RelativeLayout>
然后是另一个Activity的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/resultTitleId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/resultValue"
/>
<!-- 再添加一个 文本控件进行Result值的显示-->
<TextView
android:id="@+id/resultId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
然后就是资源文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">应用总结(Activity)</string>
<string name="app_name">Activity阶段总结</string>
<string name="smstoValue">求助短信</string>
<string name="caleValue">计算器</string>
<!-- Result.xml配置文件中控件名称-->
<string name="resultValue">等于:</string>
<string name="menuValue1">退出</string>
<string name="outOk">确认退出</string>
<string name="outCancel">取消退出</string>
<string name="menuValue2">关于</string>
</resources>
然后是Mainifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="zhou.activity"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ActivityDemo"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Result" android:label="@string/app_name"></activity>
</application>
</manifest>
最后就是相关的程序
package zhou.activity;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
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;
/**
* ?1:如果用一个公共的监听类 来控制多个点击事件
* ?2:
* @author 周周
* 完成Activity操作 sms Intent Listener Uri
*/
public class ActivityDemo extends Activity {
private Button smsButton = null;
private Button caclButton = null;
private EditText editTextOne = null;
private EditText editTextTwo = null;
/**
* 得到相应的控件
* 再添加相应的监听
*
* 添加一个公共的监听 在监听里面进行点击事件的分类
*/
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
smsButton = (Button)this.findViewById(R.id.smstoId);
caclButton = (Button)this.findViewById(R.id.cacl);
editTextOne = (EditText)this.findViewById(R.id.one);
editTextTwo = (EditText)this.findViewById(R.id.two);
smsButton.setOnClickListener(new ButtonListener());
caclButton.setOnClickListener(new ButtonListener());
}
private class ButtonListener implements OnClickListener{
public void onClick(View v) {
switch (v.getId()) {
case R.id.cacl:
String oneStr = editTextOne.getText().toString();///获取两个//关联的代码输入款的值
String TwoStr = editTextTwo.getText().toString();
//创建传输对象 进行改建为Bundle对象
Bundle b = new Bundle();
b.putString("one", oneStr);
b.putString("two", TwoStr);
Intent intent = new Intent();
intent.putExtras(b);///把这个存放数据的Bundle对象拿给Intent对象传递
intent.setClass(ActivityDemo.this, Result.class);
ActivityDemo.this.startActivity(intent);
break;
case R.id.smstoId:
///代码
Uri uri = Uri.parse("smsto:郭佳");
Intent intent2 = new Intent(Intent.ACTION_SENDTO,uri);
ActivityDemo.this.startActivity(intent2);
break;
default:
break;
}
}
}
/**
* ///添加菜单 以及相关的处理
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0,1,1,R.string.menuValue1);
menu.add(0,2,2,R.string.menuValue2);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == 1){
//做一个代码的增强
new AlertDialog.Builder(ActivityDemo.this).setTitle("退出提示").setPositiveButton(R.string.outOk, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).setNegativeButton(R.string.outCancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
System.out.println("按钮已经取消,系统不执行反应");
}
}).show();
}else if(item.getItemId() == 2){
//这个是一个关于对话框
new AlertDialog.Builder(ActivityDemo.this).setTitle("程序作者介绍")
.setMessage("姓名:周利军\n性别:男\nQ Q:271218983\n有意者请指教").show();
}
return super.onOptionsItemSelected(item);
}
}
Result.java
package zhou.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class Result extends Activity {
private TextView resultText = null;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
resultText = (TextView)this.findViewById(R.id.resultId);
///获取上一个Activity传过来的值 (程序改进 使用Bundler对数据进行封转)
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
String oneStr = bundle.getString("one");
String twoStr = bundle.getString("two");
int one = Integer.parseInt(oneStr);
int two = Integer.parseInt(twoStr);
Integer result = one * two;
resultText.setText(result.toString());
}
}
分享到:
相关推荐
NULL 博文链接:https://zhoulijun.iteye.com/blog/1109801
适合android初学者的基本控件的小例子
android 初学者 学习资料 android 初学者 学习资料 android 初学者 学习资料 android 初学者 学习资料 android 初学者 学习资料 android 初学者 学习资料
[130]vc串口通讯的例子,对初学者学习串口通讯有帮助.zip上位机开发VC串口学习资料源码下载[130]vc串口通讯的例子,对初学者学习串口通讯有帮助.zip上位机开发VC串口学习资料源码下载[130]vc串口通讯的例子,对初学...
该资源适合安卓初学者拿来学习 其中一个没有引入任何jar包, 另外一个引入jar包 不同的设计模式和思路
Extjs4.1 小例子(适合extjs初学者学习使用).直接导入myeclipse即可
android初学者学习源代码,计算器源代码,初学者可以看看这个例子
javascript基础:供新人初学者学习
android 初学者 入门资料 可供大家学习 开发指南中文版
ABAQUS 初学者小例子,适合初学者学习参考使用。
vue例子,适合初学者学习使用
一个SSM框架的小例子 比较简单 适合初学者学习 能很快上手
比较简单仪表车改造程序,可供初学者学习.zip三菱PLC编程案例源码资料编程控制器应用通讯通信例子程序实例比较简单仪表车改造程序,可供初学者学习.zip三菱PLC编程案例源码资料编程控制器应用通讯通信例子程序实例...
Android学习代码 主要针对初学者 看完以后,可以编一个俄罗期方块或者贪吃蛇之类的游戏。
都是自己自学练习时做的几个小例子 初学者一看就会
android笔记初学者必看 包含代码和知识要点 为求职做好充分准备
初学者学习PHP的100个例子 供大家学习参考
ARM学习简单例子,初学者适用 ARM学习简单例子,初学者适用,引导部分简单有注释
SQLite数据库学习的小例子,很适合初学者,里面有详细的注释!
这是一个使用mvc应用框架开发的android应用小例子,适合初学者学习