<RelativeLayout android:id="@+id/ll_tel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/ll_name"> <TextView android:id="@+id/tv_text_shop_tel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="电话:" android:textSize="20sp"/> <TextView android:id="@+id/tv_shop_tel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/tv_text_shop_tel" android:text="10086" android:textSize="20sp"/> <Button android:id="@+id/btn_call" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:onClick="call" android:text="拨打" android:layout_alignBaseline="@id/tv_shop_tel" android:textSize="20sp"/> </RelativeLayout>
<uses-permission android:name="android.permission.CALL_PHONE"/>
public void call(View v) {
// 获取电话号码栏中的号码
String num = tel_num.getText().toString();
// 如果输入不为空创建打电话的Intent
if (num.trim().length() != 0) {
Intent phoneIntent = new Intent("android.intent.action.CALL",
Uri.parse("tel:" + num));
// 启动
startActivity(phoneIntent);
}else {
// 否则Toast提示一下
Toast.makeText(ShopInfoActivity.this, "号码无效,或为空", Toast.LENGTH_LONG)
.show();
}
}
原文:http://www.cnblogs.com/superdo/p/5244575.html