小峥嵘 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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧