<Button android:id="@+id/btn_call" android:text="@string/CallNumber" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/number" />
public class MainUI4 extends Activity implements View.OnClickListener{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnCall = (Button) findViewById(R.id.btn_call); btnCall.setOnClickListener(this); }
private void call (){ System.out.println("拨打电话"); EditText etNumber = (EditText) findViewById(R.id.number); String number = etNumber.getText().toString(); Intent intent=new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:"+ number)); startActivity(intent); } @Override public void onClick(View v) { System.out.println("MainUI4拨打电话"); call(); } }