Reputation: 41
I'm having some trouble whilst following a beginner android dev program.
I am making a sort of contacts manager, and I am trying to implement right now a way to call contacts.
However since adding the callButton I have had this error on the line below my first Button, this:
button.setOnClickListener(new public void OnClick(View v){Listener() {"
I don't really understand the error so any help would be great thanks.
public class ContactPickerTester extends Activity {
public static final int PICK_CONTACT = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_picker_tester);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new public void OnClick(View v){Listener() {
public void onClick(View _view) {
Intent intent = new Intent(Intent.ACTION_PICK, Uri
.parse("content://contacts/"));
startActivityForResult(intent, PICK_CONTACT);
Button insertContactButton = (Button) findViewById(R.id.button2);
insertContactButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
insertContactWithIntent();
}
});
}
private void insertContactWithIntent() {
//inserting a new contact using intents//
Intent intent = new Intent(Intent.ACTION_INSERT,
ContactsContract.Contacts.CONTENT_URI);
startActivity(intent);
Button callButton = (Button) findViewById(R.id.button3);
callButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v){
Intent myIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("content://contacts/"));
startActivity(myIntent);
}
});
}
@Override
public void onActivityResult(int reqCode, int resCode, Intent data) {
super.onActivityResult(reqCode, resCode, data);
switch (reqCode) {
case (PICK_CONTACT): {
if (resCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
c.moveToFirst();
String name = c
.getString(c
.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
TextView tv = (TextView) findViewById(R.id.selected_contact_textview);
tv.setText(name);
}
break;
}
}
}
}
Upvotes: 0
Views: 1590
Reputation: 234857
Your syntax for creating an anonymous inner class is a little mixed up. That line should be:
button.setOnClickListener(new OnClickListener() {
public void onClick(View _view) {
Intent intent = new Intent(Intent.ACTION_PICK, Uri
.parse("content://contacts/"));
startActivityForResult(intent, PICK_CONTACT);
}
});
Upvotes: 1