In general, I try to make part of the screen of my application "scrolled", there are buttons on each page. OnCreate () MainActivity

 LayoutInflater inflater = this.getLayoutInflater(); View main_buttons_layout_view = inflater.inflate(R.layout.main_buttons_layout, flipper, false); View side_buttons_layout_view = inflater.inflate(R.layout.side_buttons_layout, flipper, false); Button leftMouseButton = (Button) main_buttons_layout_view.findViewById(R.id.LeftMouseButtonMainButtonsLayout); Button rightMouseButton = (Button) main_buttons_layout_view.findViewById(R.id.RightMouseButtonTouchpad); ViewFlipper flipper = (ViewFlipper) findViewById(R.id.flipper); //Первая и вторая странички с кнопками int layouts[] = new int[]{R.layout.main_buttons_layout, R.layout.side_buttons_layout}; for (int layout : layouts) flipper.addView(inflater.inflate(layout, null)); //Обработчики leftMouseButton.setOnTouchListener(leftMouseButtonTouchListener); rightMouseButton.setOnTouchListener(rightMouseButtonTouchListener); 

In MainActivity.xml there is

 <ViewFlipper android:id="@+id/flipper" android:layout_height="match_parent" android:layout_width="0dp" android:layout_weight="20"/> 

Accordingly, the left mouse button and the right mouse button buttons are defined in main_buttons_layout.xml . But the problem is that pressing the buttons does not work. Debazh, the code does not even go into the handlers, similarly for the buttons of the second hml - side_buttons_layout.xml. What could be the problem?

    1 answer 1

    Your layouts are loaded into variables, listeners are hung on them, but they are not added to the screen layout.

    After that, you re-upload these markup without a listener to the screen.

    Therefore, the students do not work, because You are not on those views that are displayed on the screen added.

    This should be removed as too much:

    // First and second pages with buttons

    int layouts [] = new int [] {R.layout.main_buttons_layout, R.layout.side_buttons_layout};

    for (int layout: layouts)

    flipper.addView (inflater.inflate (layout, null));

    And add markup to the screen with listeners from variables.

     flipper.addView(main_buttons_layout_view); flipper.addView(side_buttons_layout_view ); 
    • one
      Thank you. Everything Works - Yaktens Teed