android学习笔记2-------电话拨号器
思路:1>设计界面
2>设计Activity
3>编写业务层代码
效果图:
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class bohaoActivity extends Activity
{
private EditText editText;
private Button button;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText=(EditText)findViewById(R.id.editText);
button=(Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String mobileString=editText.getText().toString();
Intent intent=new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+mobileString));
bohaoActivity.this.startActivity(intent);
}
});
}
}
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class bohaoActivity extends Activity
{
private EditText editText;
private Button button;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText=(EditText)findViewById(R.id.editText);
button=(Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String mobileString=editText.getText().toString();
Intent intent=new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+mobileString));
bohaoActivity.this.startActivity(intent);
}
});
}
}
main.xml文件
[java]
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="请输入手机号:"
/>
<EditText
android:id="@+id/editText"
android:layout_height="wrap_content"
android:layout_width="match_parent"
></EditText>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拨打此号码"
></Button>
</LinearLayout>
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="请输入手机号:"
/>
<EditText
android:id="@+id/editText"
android:layout_height="wrap_content"
android:layout_width="match_parent"
></EditText>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拨打此号码"
></Button>
</LinearLayout>
添加权限:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
补充:移动开发 , Android ,