按下按钮时,只有两个听众中的一个被调用

时间:2013-12-19 06:34:43

标签: java android

我的活动中有两个按钮,两个OnClickListener对应它们。

createGroupButton = (Button) findViewById(R.id.button_create_group_in_login);
createGroupButton.setOnClickListener(new CreateGroupLoadingListener());

editProfileButton = (Button) findViewById(R.id.button_edit_profile);
editProfileButton.setOnClickListener(new ProfileEditListener());

private class ProfileEditListener implements View.OnClickListener {
    @Override
    public void onClick(View view) {

        Intent intent = new Intent(LoginActivity.this,
                EditProfileActivity.class);
        startActivity(intent);
    }
}

private class CreateGroupLoadingListener implements View.OnClickListener {
    @Override
    public void onClick(View view) {

        Intent intent = new Intent(LoginActivity.this,
                CreateGroupActivity.class);
        startActivity(intent);
    }
}

每当我点击任一按钮时,只有一个监听器被运行。例如,在一个会话中,无论是单击创建组按钮还是编辑配置文件按钮,都只运行EditProfileActivity。为什么我会出现这种行为?

1 个答案:

答案 0 :(得分:0)

试试这个,让我知道什么是o / p

为您的editprofile评论听众

createGroupButton = (Button) findViewById(R.id.button_create_group_in_login);
createGroupButton.setOnClickListener(new CreateGroupLoadingListener());

editProfileButton = (Button) findViewById(R.id.button_edit_profile);
//editProfileButton.setOnClickListener(new ProfileEditListener());
/*
private class ProfileEditListener implements View.OnClickListener {
    @Override
    public void onClick(View view) {

        Intent intent = new Intent(LoginActivity.this,
                EditProfileActivity.class);
        startActivity(intent);
    }
}
*/
private class CreateGroupLoadingListener implements View.OnClickListener {
    @Override
    public void onClick(View view) {

        Intent intent = new Intent(LoginActivity.this,
                CreateGroupActivity.class);
        startActivity(intent);
    }
}