随笔 - 23  文章 - 0 评论 - 14 trackbacks - 0

废话少说,直奔主题~!

结构如图:

Tel_DaiActivity.java代码:

public class Tel_DaiActivity extends Activity {

	private EditText tel_num_txt;
	private Button submit_btn;
	private Button reset_btn;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		findAll();
		bind();
	}

	public void findAll() {
		tel_num_txt = (EditText) this.findViewById(R.id.tel_num_txt);
		submit_btn = (Button) this.findViewById(R.id.submit_btn);
		reset_btn = (Button) this.findViewById(R.id.reset_btn);
	}

	public void bind() {
		submit_btn.setOnClickListener(mylistener);
		reset_btn.setOnClickListener(mylistener);
	}

	private View.OnClickListener mylistener = new OnClickListener() {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.submit_btn:
				Intent it = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
						+ tel_num_txt.getText().toString().trim()));
                startActivity(it);
				break;
			case R.id.reset_btn:
				tel_num_txt.setText("");
				break;
			default:
				break;
			}
		}
	};
}

main.xml代码:

<?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">
	<LinearLayout android:layout_width="fill_parent"
		android:id="@+id/linearLayout1" android:layout_height="wrap_content">
		<TextView android:text="电话号码" android:id="@+id/textView1"
			android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
		<EditText android:layout_width="wrap_content"
			android:layout_weight="1" android:id="@+id/tel_num_txt"
			android:layout_height="wrap_content" android:numeric="integer">
		</EditText>
	</LinearLayout>
	<LinearLayout android:layout_width="fill_parent"
		android:id="@+id/linearLayout2" android:layout_height="wrap_content"
		android:gravity="center">
		<Button android:text="submit" android:id="@+id/submit_btn"
			android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
		<Button android:text="reset" android:id="@+id/reset_btn"
			android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
	</LinearLayout>
</LinearLayout>

AndroidManifest.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="Tel_Dai.Jason"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4" />
    <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Tel_DaiActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

 

posted on 2011-09-19 16:57 Jwc 阅读(...) 评论(...) 编辑 收藏