小峥嵘 2020-11-21 17:57 采纳率: 0%
浏览 81

安卓编程button点击事件无效

        View indexView = View.inflate(this,R.layout.index,null);
        ImageButton imageButtonWifi = indexView.findViewById(R.id.wifi);
        imageButtonWifi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("Tag","66666");
            }
        });
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/index">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#0066FF"
        >

        <ImageView
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:background="@drawable/logo"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="20dp"
            android:layout_centerInParent="true"
            android:id="@+id/icon"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="XXXX大学"
            android:textColor="#ffffff"
            android:layout_toRightOf="@+id/icon"
            android:layout_centerInParent="true"
            android:layout_marginLeft="10dp"/>

        <ImageButton
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:background="@drawable/scan"
            android:layout_alignParentRight="true"
            android:layout_centerInParent="true"
            android:layout_marginRight="20dp"/>

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:orientation="horizontal"
        android:background="#0066FF">
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1">
            <ImageButton
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/wifi"
                android:layout_centerHorizontal="true"
                android:id="@+id/wifi"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="校园网认证"
                android:textColor="#ffffff"
                android:layout_below="@+id/wifi"
                android:layout_centerInParent="true"
                android:textSize="12dp"/>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1">
            <ImageButton
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/timetable"
                android:layout_centerHorizontal="true"
                android:id="@+id/timetable"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="课表"
                android:textColor="#ffffff"
                android:layout_below="@+id/timetable"
                android:layout_centerInParent="true"
                android:textSize="12dp"/>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1">
            <ImageButton
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/helper"
                android:layout_centerHorizontal="true"
                android:id="@+id/helper"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="班委助手"
                android:textColor="#ffffff"
                android:layout_below="@+id/helper"
                android:layout_centerInParent="true"
                android:textSize="12dp"/>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1">
            <ImageButton
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/application"
                android:layout_centerHorizontal="true"
                android:id="@+id/application"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="其它应用"
                android:textColor="#ffffff"
                android:layout_below="@+id/application"
                android:layout_centerInParent="true"
                android:textSize="12dp"/>
        </RelativeLayout>
    </LinearLayout>


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="66666"
        android:id="@+id/textBtn"/>
</LinearLayout>

另外textBtn点击也没有响应。

  • 写回答

3条回答 默认 最新

  • vigiles 2020-11-22 10:28
    关注

    看起来没问题咯,是不是日志级别太高没显示?

    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏