Cardview Click 未打开活动

2024-03-25

我的问题:

  1. no error in this project, i can run successful. screenshot

  2. 我的按钮可以在特定时间点击。

  3. 当我点击回来时,它根本不起作用。
  4. 我认为我的问题与父母有关。
  5. 我的项目父级有什么错误?

请帮帮我。

下面是我的 Java 文件:Dashboard.java

package com.example.whatisthat;

import androidx.cardview.widget.CardView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class Dashboard extends Activity implements View.OnClickListener
{

private CardView LoginBtn, CaptureBtn, AboutBtn, FeedbackBtn, IgBtn,     HelpBtn;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dashboard);
    //DEFINE CARDS
    //ADD CLICK LISTENER TO THE CARDS
    LoginBtn = findViewById(R.id.Login);
    LoginBtn.setOnClickListener(this);

    CaptureBtn = findViewById(R.id.Capture);
    CaptureBtn.setOnClickListener(this);

    AboutBtn = findViewById(R.id.About);
    AboutBtn.setOnClickListener(this);

    FeedbackBtn = findViewById(R.id.Feedback);
    FeedbackBtn.setOnClickListener(this);

    IgBtn = findViewById(R.id.Ig);
    IgBtn.setOnClickListener(this);

    HelpBtn = findViewById(R.id.Help);
    HelpBtn.setOnClickListener(this);
}

@Override
public void onClick(View view)
{
    Intent i;

    switch (view.getId())
    {
        case R.id.Login : i = new Intent(this,Login1.class);
        startActivity(i);
        break;
        case R.id.Capture : i = new Intent(this, Capture.class);
        startActivity(i);
        break;
        case R.id.About : i = new Intent(this, About.class);
        startActivity(i);
        break;
        case R.id.Feedback : i = new Intent(this, Feedback.class);
        startActivity(i);
        break;
        case R.id.Ig : i = new Intent(this, Instagram.class);
        startActivity(i);
        break;
        case R.id.Help : i = new Intent(this, Help.class);
        startActivity(i);
        break;
        default:break;
    }
}
}

下面是我的 .xml 文件:活动仪表板.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
tools:context=".Dashboard">

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="230dp"
                android:orientation="vertical"
                android:gravity="center"
                android:background="#6A287E">

                <ImageView
                    android:layout_width="90dp"
                    android:layout_height="90dp"
                    android:src="@drawable/iconfyp"
                    android:layout_gravity="center"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="DASHBOARD"
                    android:textColor="@color/colorAccent"
                    android:layout_gravity="center"
                    android:textStyle="bold"
                    android:textSize="18sp"
                    android:layout_marginTop="10dp"
                    />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginTop="215dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="135dp"
                    android:orientation="horizontal"
                    android:layout_marginBottom="10dp">

                    <androidx.cardview.widget.CardView
                        android:foreground="?   android:attr/selectableItemBackground"
                        android:focusable="true"
                        android:clickable="true"
                        android:id="@+id/Login"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:layout_marginRight="5dp"
                        android:orientation="vertical">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <ImageView
                                android:layout_width="50dp"
                                android:id="@+id/imageView1"
                                android:layout_height="50dp"
                                android:src="@drawable/people"
                                android:layout_centerInParent="true"/>

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="LOGIN"
                                android:textSize="16sp"
                                android:layout_below="@+id/imageView1"
                                android:layout_centerHorizontal="true"
                                android:layout_marginTop="10dp"
                                android:layout_marginBottom="10dp"/>

                            <Button
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:id="@+id/buttonLogin"
                                    android:background="@android:color/transparent"/>

                        </RelativeLayout>
                    </androidx.cardview.widget.CardView>
                    <androidx.cardview.widget.CardView
                        android:foreground="?    android:attr/selectableItemBackground"
                        android:focusable="true"
                        android:clickable="true"
                        android:id="@+id/Capture"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:layout_marginLeft="5dp"
                        android:orientation="vertical">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <ImageView
                                android:layout_width="50dp"
                                android:id="@+id/imageView2"
                                android:layout_height="50dp"
                                android:src="@drawable/cameraa"
                                android:layout_centerInParent="true"/>

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="CAPTURE"
                                android:textSize="16sp"
                                android:layout_below="@+id/imageView2"
                                android:layout_centerHorizontal="true"
                                android:layout_marginTop="10dp"
                                android:layout_marginBottom="10dp"/>

                            <Button
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:id="@+id/buttonCapture"
                                    android:background="@android:color/transparent"/>

                        </RelativeLayout>
                    </androidx.cardview.widget.CardView>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="135dp"
                    android:orientation="horizontal"
                    android:layout_marginBottom="10dp">

                    <androidx.cardview.widget.CardView
                        android:foreground="?    android:attr/selectableItemBackground"
                        android:focusable="true"
                        android:clickable="true"
                        android:id="@+id/About"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:layout_marginRight="5dp"
                        android:orientation="vertical">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <ImageView
                                android:layout_width="50dp"
                                android:id="@+id/imageView3"
                                android:layout_height="50dp"
                                android:src="@drawable/aboutt"
                                android:layout_centerInParent="true"/>

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="ABOUT"
                                android:textSize="16sp"
                                android:layout_below="@+id/imageView3"
                                android:layout_centerHorizontal="true"
                                android:layout_marginTop="10dp"
                                android:layout_marginBottom="10dp"/>

                            <Button
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:id="@+id/buttonAbout"
                                    android:background="@android:color/transparent"/>

                        </RelativeLayout>
                    </androidx.cardview.widget.CardView>
                    <androidx.cardview.widget.CardView
                        android:foreground="?    android:attr/selectableItemBackground"
                        android:focusable="true"
                        android:clickable="true"
                        android:id="@+id/Feedback"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:layout_marginLeft="5dp"
                        android:orientation="vertical">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <ImageView
                                android:layout_width="50dp"
                                android:id="@+id/imageView4"
                                android:layout_height="50dp"
                                android:src="@drawable/feedback"
                                android:layout_centerInParent="true"/>

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="FEEDBACK "
                                android:textSize="16sp"
                                android:layout_below="@+id/imageView4"
                                android:layout_centerHorizontal="true"
                                android:layout_marginTop="10dp"
                                android:layout_marginBottom="10dp"/>

                            <Button
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:id="@+id/buttonFeedback"
                                    android:background="@android:color/transparent"/>

                        </RelativeLayout>
                    </androidx.cardview.widget.CardView>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="135dp"
                    android:orientation="horizontal"
                    android:layout_marginBottom="10dp">

                    <androidx.cardview.widget.CardView
                        android:foreground="?    android:attr/selectableItemBackground"
                        android:focusable="true"
                        android:clickable="true"
                        android:id="@+id/Ig"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:layout_marginRight="5dp"
                        android:orientation="vertical">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <ImageView
                                android:layout_width="50dp"
                                android:id="@+id/imageView5"
                                android:layout_height="50dp"
                                android:src="@drawable/instagram"
                                android:layout_centerInParent="true"/>

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="INSTAGRAM"
                                android:textSize="16sp"
                                android:layout_below="@+id/imageView5"
                                android:layout_centerHorizontal="true"
                                android:layout_marginTop="10dp"
                                android:layout_marginBottom="10dp"/>

                            <Button
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:id="@+id/buttonIg"
                                    android:background="@android:color/transparent"/>

                        </RelativeLayout>
                    </androidx.cardview.widget.CardView>
                    <androidx.cardview.widget.CardView
                        android:foreground="?    android:attr/selectableItemBackground"
                        android:focusable="true"
                        android:clickable="true"
                        android:id="@+id/Help"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:layout_marginLeft="5dp"
                        android:orientation="vertical">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <ImageView
                                android:layout_width="50dp"
                                android:id="@+id/imageView6"
                                android:layout_height="50dp"
                                android:src="@drawable/help"
                                android:layout_centerInParent="true"/>

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="HELP"
                                android:textSize="16sp"
                                android:layout_below="@+id/imageView6"
                                android:layout_centerHorizontal="true"
                                android:layout_marginTop="10dp"
                                android:layout_marginBottom="10dp"/>

                            <Button
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:id="@+id/buttonHelp"
                                    android:background="@android:color/transparent"/>

                        </RelativeLayout>
                    </androidx.cardview.widget.CardView>
                </LinearLayout>
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
</ScrollView>
</RelativeLayout>

那么你必须首先从中删除空间android:foreground="?android:attr/selectableItemBackground"并将其添加到所有按钮

android:clickable="false"

如果您想打开活动Button然后你必须把setOnClickListener到 Button 。否则如果你想用以下方式打开 ActivityCardview你必须把setOnClickListener到卡片视图。

用这个来OnClick Method:

@Override
    public void onClick(View view) {
        if (view==LoginBtn){
 startActivity(new Intent(this,Login1.class));
        }else if(view==Capture){
startActivity(new Intent(this,Capture.class));

      }
     //Do rest by yourself.

    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Cardview Click 未打开活动 的相关文章

  • 使用 JDBC 连接到 PostgreSql 的本地实例

    我在 Linux 机器上有一个正在运行的 PostgreSql 本地实例 当我使用psql来自 shell 的命令我成功登录 没有任何问题 我需要通过 JDBC 连接到 PostgreSql 但我不知道我到底应该传递什么url参数为Driv
  • 如何在android中的谷歌地图上聚焦标记

    我只是想知道我们是否可以关注 Android 应用程序中添加的标记 如果是 怎么办 或者有没有其他方法可以完成这项任务 可以说我使用下面的代码添加了一个标记 map addMarker new MarkerOptions title tit
  • 如何在 60 分钟后删除共享首选项

    我想存储登录数据 但希望在 60 分钟后删除该数据 执行此操作的正确方法是什么 在这 60 分钟内可以关闭 停止 打开应用程序 我不想使用内部数据库 这是我的访问代码SharedPreferences sharedpreferences g
  • 模拟器无法加载

    我正在使用 hello android 教程并通过 eclipse 创建 avd 启动模拟器时不使用图像 它只是显示一个黑色的后屏 中间有 ANDROID 字样 并且在 ANDROID 字样的末尾有一个闪烁的光标 我已按照 T 的步骤安装
  • Android 认为我没有关闭数据库!为什么?

    我有一个 SQLiteDatabase 数据成员 我在 onCreate 中初始化它 并在 onPause onStop 和 onDestroy 中调用 close 它在 onResume 中重新初始化 它似乎运行得很好 但当我查看调试器时
  • 双屏 Android Studio 中不显示自动补全

    我刚刚从 Eclipse 切换到 Android Studio IntelliJ 我不明白自动补全是如何工作的 我尝试了 Control Space Control Shift Space 但没有相关建议 不在 Java 文件中 也不在布局
  • IntelliJ Idea:将简单的 Java servlet(无 JSP)部署到 Tomcat 7

    我尝试按照教程进行操作here http wiki jetbrains net intellij Creating a simple Web application and deploying it to Tomcat部署 servlet
  • 使用 Proguard 通过 Dropbox.com 库混淆 Android 应用程序

    我刚刚创建了一个需要 Dropbox com API 库的 Android 应用程序 我现在尝试在 发布 模式下构建应用程序 并希望在代码上运行混淆器以对其进行混淆 但是 每当我尝试运行 Proguard 时 都会收到以下错误 Progua
  • 类更改(例如字段添加或删除)是否保持 Serialized 的向后兼容性?

    我有一个关于 Java 序列化的问题 在这种情况下 您可能需要修改可序列化类并保持向后兼容性 我有丰富的 C 经验 所以请允许我将 Java 与 NET 进行比较 在我的Java场景中 我需要使用Java的运行时序列化机制序列化一个对象 并
  • 按降序排序映射java8 [重复]

    这个问题在这里已经有答案了 private static
  • java实现excel价格、收益率函数[关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • Android计算两个日期之间的天数

    我编写了以下代码来查找两个日期之间的天数 startDateValue new Date startDate endDateValue new Date endDate long diff endDateValue getTime star
  • 我所有的 java 应用程序现在都会抛出 java.awt.headlessException

    所以几天前我有几个工作Java应用程序使用Swing图书馆 JFrame尤其 他们都工作得很好 现在他们都抛出了这个异常 java awt headlessexception 我不知道是什么改变了也许我的Java版本不小心更新了 谢谢你尽你
  • onPrepareOptionsMenu 复制 ActionBar 中的项目

    当我使用 onPrepareOptionsMenu 添加菜单项时 该菜单项会在操作栏中复制其自身 我正在使用片段并在主要活动的 ActionBar 中创建初始菜单 如下所示 Override public boolean onCreateO
  • Android ScrollView,检查当前是否滚动

    有没有办法检查标准 ScrollView 当前是否正在滚动 方向是向上还是向下并不重要 我只需要检查它当前是否正在滚动 ScrollView当前形式不提供用于检测滚动事件的回调 有两种解决方法可用 1 Use a ListView并实施On
  • TabLayout 的不同 tabMode

    我正在使用 ViewPager 和 TabLayout 如果选项卡可以放置在显示 tabMode 上 则它们必须是 app tabMode fixed else app tabMode scrollable 我怎样才能做到这一点 我不明白你
  • 如何正确处理 ListView 内的 Android EditText 输入?

    在我的应用程序中 我有一个在 a 中添加 删除 编辑记录的活动SortedMap 该活动作为以下活动的延伸实施ListActivity 我已经实现了自定义ArrayAdapter对于收藏品 Every ListView项目 对应于基础记录
  • 使用 DBCP 配置 Tomcat

    在闲置一段时间 几个小时 后 我们收到了 CommunicationsException 来自 DBCP 错误消息 在异常中 位于这个问题的末尾 但我没有看到任何配置文件中定义的 wait timeout 我们应该看哪里 在 tomcat
  • Java 的“&&”与“&”运算符

    我使用的示例来自 Java Herbert Schildt 的完整参考文献 第 12 版 Java 是 14 他给出了以下 2 个示例 如果阻止 第一个是好的 第二个是错误的 因此发表评论 public class PatternMatch
  • 如何用LoaderManager自动重新查询

    我有一个应用程序显示来自 SQLite DB 的数据 并且数据不断变化 所以显然 我认为我应该使用 LoaderManager 来显示数据 我读过一些关于将 LoaderManager 与 SQLite 结合使用的内容 然后看到了亚历克斯

随机推荐