Reputation: 11
Im trying to make an app with buttons to call different phone numbers. I have this: package com.BigTooth.Apps.Recromax;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.Intent;
import android.content.*;
import android.net.Uri;
import android.view.View.OnClickListener;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
private void phoneCall1()
{
String phoneCallUri = "tel:4078421430";
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
phoneCallIntent.setData(Uri.parse(phoneCallUri));
startActivity(phoneCallIntent);
}
// add button listener
button.setOnClickListener(new OnClickListener() {
private void phoneCall()
{
String phoneCallUri = "tel:8889807091";
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
phoneCallIntent.setData(Uri.parse(phoneCallUri));
startActivity(phoneCallIntent);}
}
}
In my MainActivity.java file. Its telling me that isn't correct. Please help!!!
Upvotes: 0
Views: 62
Reputation: 2211
button.setOnClickListener
is in the wrong place. Also, the onClickListener is a bit wring. Should be:
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.Intent;
import android.content.*;
import android.net.Uri;
import android.view.View.OnClickListener;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.youButtonId);
Button button1 = (Button) findViewById(R.id.youButtonId1);
// add button listener
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
phoneCall();
}
});
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
phoneCall1();
}
});
}
private void phoneCall()
{
String phoneCallUri = "tel:8889807091";
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
phoneCallIntent.setData(Uri.parse(phoneCallUri));
startActivity(phoneCallIntent);
}
private void phoneCall1()
{
String phoneCallUri = "tel:4078421430";
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
phoneCallIntent.setData(Uri.parse(phoneCallUri));
startActivity(phoneCallIntent);
}
}
Upvotes: 1