設置函數的大小
android:hint="@string/_love" -->設計默認值得大小
android:ems="10"
android:inputType="textMultiLine" />
6邏輯設計
public class MainActivity extends Activity implements OnClickListener{
Button Call_other;
Button Call_wangqi;
Button Call_xiaoyu;
Button Send_other;
Button Send_wangqi;
Button Send_xiaoyu;
EditText Nummber_edit;
EditText Talk_Edit;
@Override
A-定義控件便於尋找
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Nummber_edit = (EditText)B-findViewById(R.id.NummberText); 通過findViewById來找到控制控件
Talk_Edit= (EditText)findViewById(R.id.editText1);
Call_other = (Button)findViewById(R.id.Call_otherButton);
Call_wangqi= (Button)findViewById(R.id.Call_mangqi);;
Call_xiaoyu= (Button)findViewById(R.id.Call_xiaoyuButton);;
Send_other= (Button)findViewById(R.id.Send_friend);
Send_wangqi= (Button)findViewById(R.id.Send_wangqi);
Send_xiaoyu= (Button)findViewById(R.id.Send_xiaoyu);
C -public class MainActivity extends Activity implements OnClickListener{
將主類實現OnClickListener接口可以對控件通過一個OnClick控制
D:1.在文件中設計按鈕的事件
private void MyCallOther(){
String num = Nummber_edit.getText().toString();
if(TextUtils.isEmpty(num)){ ---判斷字符中的文字是否為空
Toast.makeText(MainActivity.this, "電話為空了>.<", 0
--顯示的時間).show();--土司生成
return ;
}else{
Intent intent = new Intent();----打電話的程序重要的一點事必須啟動一個Intent的程序
Toast.makeText(MainActivity.this, "電話打向"+num, 0).show();--必須show出來
intent.setAction(Intent.ACTION_CALL);---設置打電話的設置
intent.setData(Uri.parse("tel:"+num));---設置電環號碼
startActivity(intent);---啟動事件
return;
}
}
private void MyCallxiaoyu(){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "Love曉宇691526", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"691526"));
startActivity(intent);
return ;
}
private void CallWangqi (){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "打給討厭鬼王琪>.<", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"652008"));
startActivity(intent);
}
7.定義單擊清空設置
private void ClearEdi(){
Nummber_edit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Nummber_edit.setText("");
}
});
Talk_Edit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Talk_Edit.setText("");
}
});
8>添加系統的單機事件
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.Call_otherButton : --通過R地址尋找控件
MyCallOther();ClearEdi(); 執行對應的方法
break;
case R.id.Call_xiaoyuButton :
MyCallxiaoyu();
break;
case R.id.Call_mangqi:
CallWangqi ();ClearEdi();
break;
case R.id.Send_friend:
SendFriend();ClearEdi();
break;
case R.id.Send_wangqi:
SendWangqi();ClearEdi();
break;
case R.id.Send_xiaoyu:
SendXiaoyu();ClearEdi();
break;
default:
// ClearEdi();
}
}
9:添加權限
----------------------------------------------------------------------
原碼:
-----
package com.example.love_happy;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Telephony.Sms;
import android.app.Activity;
import android.content.Intent;
import android.telephony.gsm.SmsManager;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
Button Call_other;
Button Call_wangqi;
Button Call_xiaoyu;
Button Send_other;
Button Send_wangqi;
Button Send_xiaoyu;
EditText Nummber_edit;
EditText Talk_Edit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Nummber_edit = (EditText)findViewById(R.id.NummberText);
Talk_Edit= (EditText)findViewById(R.id.editText1);
Call_other = (Button)findViewById(R.id.Call_otherButton);
Call_wangqi= (Button)findViewById(R.id.Call_mangqi);;
Call_xiaoyu= (Button)findViewById(R.id.Call_xiaoyuButton);;
Send_other= (Button)findViewById(R.id.Send_friend);
Send_wangqi= (Button)findViewById(R.id.Send_wangqi);
Send_xiaoyu= (Button)findViewById(R.id.Send_xiaoyu);
Call_other.setOnClickListener(MainActivity.this);
Call_wangqi.setOnClickListener(MainActivity.this);
Call_xiaoyu.setOnClickListener(MainActivity.this);
Send_other.setOnClickListener(MainActivity.this);
Send_wangqi.setOnClickListener(MainActivity.this);
Send_xiaoyu.setOnClickListener(MainActivity.this);
Nummber_edit.setOnClickListener(MainActivity.this);
Talk_Edit.setOnClickListener(MainActivity.this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void MyCallOther(){
String num = Nummber_edit.getText().toString();
if(TextUtils.isEmpty(num)){
Toast.makeText(MainActivity.this, "電話為空了>.<", 0).show();
return ;
}else{
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "電話打向"+num, 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+num));
startActivity(intent);
return;
}
}
private void MyCallxiaoyu(){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "Love曉宇691526", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"691526"));
startActivity(intent);
return ;
}
private void CallWangqi (){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "打給討厭鬼王琪>.<", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"652008"));
startActivity(intent);
}
private void SendFriend(){
String number = Nummber_edit.getText().toString();
String sms = Talk_Edit.getText().toString();
if(TextUtils.isEmpty(number)||TextUtils.isEmpty(sms)){
Toast.makeText(MainActivity.this, "信息為空了>.<", 0).show();
return ;
}else{
Toast.makeText(MainActivity.this, "信息發向了"+number, 0).show();
SmsManager message = SmsManager.getDefault();
message.sendTextMessage(number, null, sms, null,null);
Toast.makeText(MainActivity.this, "信息發送成功>.<", 0).show();
}
}
private void SendWangqi(){
String sms = Talk_Edit.getText().toString();
Nummber_edit.setText("");
if(TextUtils.isEmpty(sms)){
Toast.makeText(MainActivity.this, "為空了>.<", 0).show();
return;
}
Toast.makeText(MainActivity.this, "信息發向了652008", 0).show();
SmsManager message = SmsManager.getDefault();
message.sendTextMessage("652008", null, sms, null, null);
Toast.makeText(MainActivity.this, "信息發送成功>.<", 0).show();
}
private void SendXiaoyu(){
String sms = Talk_Edit.getText().toString();
Nummber_edit.setText("");
if(TextUtils.isEmpty(sms)){
Toast.makeText(MainActivity.this, "為空了>.<", 0).show();
return;
}
Toast.makeText(MainActivity.this, "信息發向了691526", 0).show();
SmsManager message = SmsManager.getDefault();
message.sendTextMessage("691526", null, sms, null, null);
Toast.makeText(MainActivity.this, "信息發送成功>.<", 0).show();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.Call_otherButton :
MyCallOther();ClearEdi();
break;
case R.id.Call_xiaoyuButton :
MyCallxiaoyu();
break;
case R.id.Call_mangqi:
CallWangqi ();ClearEdi();
break;
case R.id.Send_friend:
SendFriend();ClearEdi();
break;
case R.id.Send_wangqi:
SendWangqi();ClearEdi();
break;
case R.id.Send_xiaoyu:
SendXiaoyu();ClearEdi();
break;
default:
// ClearEdi();
}
}
private void ClearEdi(){
Nummber_edit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Nummber_edit.setText("");
}
});
Talk_Edit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Talk_Edit.setText("");
}
});
}
}
----
Sting:
Love_曉宇
Settings
Hello world!
請輸入電話號碼或收信人
Call_Other
Love_曉宇
Call_wangqi
Call_王琪>.
風聲細語
Send_王琪
Send_曉宇
希望你開心..
----
R
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.example.love_happy;
public final class R {
public static final class attr {
}
public static final class dimen {
/** Default screen margins, per the Android Design guidelines.
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
*/
public static final int activity_horizontal_margin=0x7f040000;
public static final int activity_vertical_margin=0x7f040001;
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int Call_mangqi=0x7f080003;
public static final int Call_otherButton=0x7f080001;
public static final int Call_xiaoyuButton=0x7f080002;
public static final int NummberText=0x7f080000;
public static final int Send_friend=0x7f080008;
public static final int Send_wangqi=0x7f080006;
public static final int Send_xiaoyu=0x7f080007;
public static final int action_settings=0x7f080009;
public static final int editText1=0x7f080005;
public static final int textView1=0x7f080004;
}
public static final class layout {
public static final int activity_main=0x7f030000;
}
public static final class menu {
public static final int main=0x7f070000;
}
public static final class string {
public static final int SMS_please=0x7f050003;
public static final int Talk_Message=0x7f050008;
public static final int _love=0x7f05000b;
public static final int action_settings=0x7f050001;
public static final int app_name=0x7f050000;
public static final int call_other=0x7f050004;
public static final int call_wangqi=0x7f050007;
public static final int call_鐜嬬惇=0x7f050006;
public static final int hello_world=0x7f050002;
public static final int love_xiaoyu=0x7f050005;
public static final int send_wangqi=0x7f050009;
public static final int send_xiaoyu=0x7f05000a;
}
public static final class style {
/**
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
API 11 theme customizations can go here.
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
API 14 theme customizations can go here.
*/
public static final int AppBaseTheme=0x7f060000;
/** Application theme.
All customizations that are NOT specific to a particular API-level can go here.
*/
public static final int AppTheme=0x7f060001;
}
}
----
設置函數的大小
android:hint="@string/_love" -->設計默認值得大小
android:ems="10"
android:inputType="textMultiLine" />
6邏輯設計
public class MainActivity extends Activity implements OnClickListener{
Button Call_other;
Button Call_wangqi;
Button Call_xiaoyu;
Button Send_other;
Button Send_wangqi;
Button Send_xiaoyu;
EditText Nummber_edit;
EditText Talk_Edit;
@Override
A-定義控件便於尋找
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Nummber_edit = (EditText)B-findViewById(R.id.NummberText); 通過findViewById來找到控制控件
Talk_Edit= (EditText)findViewById(R.id.editText1);
Call_other = (Button)findViewById(R.id.Call_otherButton);
Call_wangqi= (Button)findViewById(R.id.Call_mangqi);;
Call_xiaoyu= (Button)findViewById(R.id.Call_xiaoyuButton);;
Send_other= (Button)findViewById(R.id.Send_friend);
Send_wangqi= (Button)findViewById(R.id.Send_wangqi);
Send_xiaoyu= (Button)findViewById(R.id.Send_xiaoyu);
C -public class MainActivity extends Activity implements OnClickListener{
將主類實現OnClickListener接口可以對控件通過一個OnClick控制
D:1.在文件中設計按鈕的事件
private void MyCallOther(){
String num = Nummber_edit.getText().toString();
if(TextUtils.isEmpty(num)){ ---判斷字符中的文字是否為空
Toast.makeText(MainActivity.this, "電話為空了>.<", 0
--顯示的時間).show();--土司生成
return ;
}else{
Intent intent = new Intent();----打電話的程序重要的一點事必須啟動一個Intent的程序
Toast.makeText(MainActivity.this, "電話打向"+num, 0).show();--必須show出來
intent.setAction(Intent.ACTION_CALL);---設置打電話的設置
intent.setData(Uri.parse("tel:"+num));---設置電環號碼
startActivity(intent);---啟動事件
return;
}
}
private void MyCallxiaoyu(){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "Love曉宇691526", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"691526"));
startActivity(intent);
return ;
}
private void CallWangqi (){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "打給討厭鬼王琪>.<", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"652008"));
startActivity(intent);
}
7.定義單擊清空設置
private void ClearEdi(){
Nummber_edit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Nummber_edit.setText("");
}
});
Talk_Edit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Talk_Edit.setText("");
}
});
8>添加系統的單機事件
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.Call_otherButton : --通過R地址尋找控件
MyCallOther();ClearEdi(); 執行對應的方法
break;
case R.id.Call_xiaoyuButton :
MyCallxiaoyu();
break;
case R.id.Call_mangqi:
CallWangqi ();ClearEdi();
break;
case R.id.Send_friend:
SendFriend();ClearEdi();
break;
case R.id.Send_wangqi:
SendWangqi();ClearEdi();
break;
case R.id.Send_xiaoyu:
SendXiaoyu();ClearEdi();
break;
default:
// ClearEdi();
}
}