<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/v1"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/v2"
android:id="@+id/textView2"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="68dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/v3"
android:id="@+id/textView3"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/v4"
android:id="@+id/button"
android:layout_alignTop="@+id/textView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/v4"
android:id="@+id/button2"
android:layout_alignTop="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/v4"
android:id="@+id/button3"
android:layout_alignBottom="@+id/textView3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
&#13;
<resources>
<string name="app_name">Help</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="v1">01734208484</string>
<string name="v2">01734208479</string>
<string name="v3">01828601248</string>
<string name="v4">call</string>
</resources>
&#13;
![
package com.example.tushar.help;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
Button call;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
call = (Button) findViewById(R.id.button);
call.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
makecall();
}
});
}
protected void makecall() {
Log.i("Make call", "");
Intent phoneIntent = new Intent(Intent.ACTION_CALL);
phoneIntent.setData(Uri.parse("tel:01734208484"));
try {
startActivity(phoneIntent);
finish();
Log.i("Finished making a call...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"Call faild, please try again later.", Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
&#13;
] 1我正在尝试创建一个预加载联系人列表的应用程序。我添加了多个呼叫按钮,但我无法使用此按钮拨打电话。之前我学会了使用此代码拨打电话 http://www.tutorialspoint.com/android/android_phone_calls.htm 但是当涉及到另一个调用按钮时,我无法执行java代码。