Second onClick listener in a new activity

user5064340

I just started to learn Java. I know some C++, but you know, I am just a novice. I have a problem with a button. I a main activity there are 3 buttons with onClick discovered by switch. By clicking on one of the buttons you're redirected to another activity where I need to create a new button.

The code responsible for MainScreen buttons looks like this (and it works):

public class MainScreen extends Activity implements View.OnClickListener {

Button act_2x2, act_3x3, act_4x4;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_screen);

    act_2x2 = (Button) findViewById(R.id.Activity_2x2);
    act_3x3 = (Button) findViewById(R.id.Activity_3x3);
    act_4x4 = (Button) findViewById(R.id.Activity_4x4);

    act_2x2.setOnClickListener(this);
    act_3x3.setOnClickListener(this);
    act_4x4.setOnClickListener(this);
}

@Override
public void onClick(View view) {
    switch(view.getId())
    {
        case R.id.Activity_2x2:
            Intent inent1 = new Intent(this, macierz_2x2.class);
            startActivity(inent1);
            break;

        case R.id.Activity_3x3:
            Intent inent2 = new Intent(this, macierz_3x3.class);
            startActivity(inent2);
            break;

        case R.id.Activity_4x4:
            Intent inent3 = new Intent(this, macierz_4x4.class);
            startActivity(inent3);
            break;
    }

And it is okay, I can normally enter the new activity, for example Activity_2x2. Here, in 2x2 class I've created a new OnClickListener and when I click on it, nothing happens. I am sitting here for two hours with debugger, it is saying that I don't have permissions, but It is impossible, because it is just a simple button. I am using Android Studio and just don't know how to debug correctly.

Here is the definition:

public class macierz_2x2 extends MainScreen implements View.OnClickListener{

Button b_2x2;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_2x2);
    b_2x2 = (Button) findViewById(R.id.button_2x2);
    b_2x2.setOnClickListener(this);
}

public void OnClick(View view) { what happens after clicking }

I know, that this problem is somewhere in overriding and extending, but no idea, why the compiller is letting this being compiled.

If someone have any idea, I will be grateful.

ps. I don't need an answer, just a point, what is wrong.

Blackbelt
public class macierz_2x2 extends MainScreen implements View.OnClickListener{

MainScreen already implements View.OnClickListener. Remove it from the definition of your class.

public class macierz_2x2 extends MainScreen {

is enough. You can override onClick on your macierz_2x2 activity

@Override
public void onClick(View view) {
    switch(view.getId()) {
      R.id.button_2x2:
        // do something
        break;
      default:
        super.onClick(view);
        break;
     }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to set onclick listener recyclerview and start new activity on each click

From Dev

Launching a new activity with onClick

From Dev

GridView onclick to a new activity

From Dev

Add onclick event listener to transparent activity

From Dev

Implement listener for onClick of a checkbox in activity from an adapter

From Dev

onClick to a new activity but the app stopped

From Dev

new to android understanding listener = (OnItemSelectedListener) activity

From Dev

How to attach an onclick listener to Android Studio's navigation drawer activity?

From Dev

How to open a new activity from onClick() of fancybutton?

From Dev

OnClick imageview to take you from mainactivity to a second activity class?

From Dev

activity to activity callback listener

From Dev

activity to activity callback listener

From Dev

SQLite Listview onclick filters db to open result in new activity

From Dev

ListView Adapter - OnClick to launch a new Activity & OnLongClick to launch a ContextActionBar

From Dev

How to navigate to new activity by using two spinners and onclick submit button?

From Dev

React: component only rendering new values on second onClick of button

From Dev

Activity Listener Implementation?

From Dev

Activity Listener Implementation?

From Dev

Stop a location listener activity when the user presses the back button, or when a new intent is made

From Dev

Javascript global onclick listener

From Dev

MapView onCLick Event Listener

From Dev

Javascript onclick listener

From Dev

Nested onClick Listener

From Dev

The wrong onclick listener is triggered

From Dev

Menu Not Showing In Second Activity

From Dev

second Activity to drawer fragment

From Dev

Issues with creating second activity

From Dev

Menu Not Showing In Second Activity

From Dev

Second activity will not populate

Related Related

  1. 1

    how to set onclick listener recyclerview and start new activity on each click

  2. 2

    Launching a new activity with onClick

  3. 3

    GridView onclick to a new activity

  4. 4

    Add onclick event listener to transparent activity

  5. 5

    Implement listener for onClick of a checkbox in activity from an adapter

  6. 6

    onClick to a new activity but the app stopped

  7. 7

    new to android understanding listener = (OnItemSelectedListener) activity

  8. 8

    How to attach an onclick listener to Android Studio's navigation drawer activity?

  9. 9

    How to open a new activity from onClick() of fancybutton?

  10. 10

    OnClick imageview to take you from mainactivity to a second activity class?

  11. 11

    activity to activity callback listener

  12. 12

    activity to activity callback listener

  13. 13

    SQLite Listview onclick filters db to open result in new activity

  14. 14

    ListView Adapter - OnClick to launch a new Activity & OnLongClick to launch a ContextActionBar

  15. 15

    How to navigate to new activity by using two spinners and onclick submit button?

  16. 16

    React: component only rendering new values on second onClick of button

  17. 17

    Activity Listener Implementation?

  18. 18

    Activity Listener Implementation?

  19. 19

    Stop a location listener activity when the user presses the back button, or when a new intent is made

  20. 20

    Javascript global onclick listener

  21. 21

    MapView onCLick Event Listener

  22. 22

    Javascript onclick listener

  23. 23

    Nested onClick Listener

  24. 24

    The wrong onclick listener is triggered

  25. 25

    Menu Not Showing In Second Activity

  26. 26

    second Activity to drawer fragment

  27. 27

    Issues with creating second activity

  28. 28

    Menu Not Showing In Second Activity

  29. 29

    Second activity will not populate

HotTag

Archive