简体   繁体   English

视图类型中的方法setOnClickListener(View.OnClickListener)不适用于参数()

[英]The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments ()

I'm having some trouble whilst following a beginner android dev program. 在遵循初学者的android开发程序时遇到了一些麻烦。

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: 但是,由于添加了callButton,因此我在第一个Button下方的行上遇到了此错误,这是:

button.setOnClickListener(new public void OnClick(View v){Listener() {" 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;
        }
        }
    }
}

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);
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 视图类型中的方法setOnClickListener(View.OnClickListener)不适用于自变量(起点) - The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (startingpoint) android错误:“视图类型中的方法setOnClickListener(View.OnClickListener)不适用于参数(new OnClickListener(){})” - android error: “The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){})” 视图类型中的方法setOnClickListener(View.OnClickListener)不适用于自变量(新DialogInterface.OnClickListener(){}) - The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new DialogInterface.OnClickListener(){}) 类型View中的setOnClickListener(View.OnClickListener)不适用于参数(SequencerActivity)back.setOnClickListener(this); - setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (SequencerActivity) back.setOnClickListener(this); 类型View中的Java Android - setOnClickListener(View.OnClickListener)不适用于参数(new OnClickListener(){}) - Java Android - setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){}) 未为类型imageButton1定义方法setOnClickListener(new View.OnClickListener(){}) - The method setOnClickListener(new View.OnClickListener(){}) is undefined for the type imageButton1 类型中的方法调用(活动) <type> 不适用于参数(新的View.OnClickListener(){}) - The method call(Activity) in the type <type> is not applicable for the arguments (new View.OnClickListener(){}) 函数setOnClickListener(new View.OnClickListener() - Function setOnClickListener(new View.OnClickListener() setOnclickListener vs Activity实现View.OnClickListener - setOnclickListener vs Activity implements View.OnClickListener setOnClickListener(this) 和 setOnClickListener(new View.OnClickListener(){}) 内存泄漏 - Memory leak with setOnClickListener(this) and setOnClickListener(new View.OnClickListener(){})
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM