Example of Solution to Invalid Button Click Event in Android Programming

  • 2021-08-17 01:10:22
  • OfStack

In this paper, an example is given to describe the solution to the invalid Button click event in Android programming. Share it for your reference, as follows:

When encountering such a problem, a click event was added to the button at the top of an interface, but it didn't respond anyway. The three buttons placed at the bottom of the interface all had corresponding click events. Baidu has only two possibilities for one click:

1. button is not initialized or button is initialized multiple times, resulting in confusion.
2. button click event is incorrectly written and cannot be monitored.

But what I'm sure is that there is nothing wrong with these. The reason I found later is that the layout of scroll at the bottom overrides the layout of button at the top and uses fill_parent, so I can't get the click event. The error code is as follows:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:gravity="center_vertical" >
  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="<span style="font-family: Arial, Helvetica, sans-serif;">fill_parent</span><span style="font-family: Arial, Helvetica, sans-serif;">"</span>
    android:orientation="horizontal" >
    <Button
      android:id="@+id/canshusback"
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:layout_marginLeft="5dp"
      android:layout_marginTop="5dp"
      android:background="@drawable/last" />
  </LinearLayout>
  <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <RelativeLayout
      android:id="@+id/allti"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:gravity="center_vertical" >

Later, after setting the top button to a height of 40dp, set the bottom scroll at a distance from the top, and you can monitor the button.

For more readers interested in Android related content, please check the topics on this site: "Introduction and Advanced Tutorial of Android Development", "Summary of Android Debugging Skills and Common Problem Solutions", "Summary of activity Operation Skills of Android Programming", "Summary of Android Operation Skills of json Format Data", "Summary of Android Database Operation Skills", "Summary of Android File Operation Skills", "Summary of Android Resource Operation Skills" and "Summary of Android Control Usage"

I hope this article is helpful to everyone's Android programming.


Related articles: