- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Android 编程新手,在我移动布局中的按钮后,我的应用程序开始发生一些奇怪的事情。因此,有一个按钮(开始),单击该按钮会启动另一个 Activity 。这是代码。
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button startbutton = (Button) findViewById(R.id.button1);
startbutton.setOnClickListener(new View.OnClickListener() { //STARTBUTTON
@Override
public void onClick(View arg0) { //LO QUE HACE EL START BUTTON
Intent intent = new Intent(MainActivity.this, JugarActivity.class);
startActivity(intent);
}
});
}
}
我的问题是,在测试我的应用程序时,当我单击开始按钮时没有任何反应,但是当我单击布局中的另一个按钮(button4)时,它确实会将我发送到第二个 Activity 。这是我的 Activity_main.xml,以备需要时使用。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:minWidth="200dp"
android:text="@string/Start"
android:textSize="30sp" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="200dp"
android:minHeight="50dp"
android:minWidth="200dp"
android:text="@string/Jugarporcontinente"
android:textSize="30sp" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="200dp"
android:text="@string/Aprende"
android:textSize="30sp" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="200dp"
android:text="@string/Puntajes"
android:textSize="30sp" />
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="200dp"
android:text="@string/Opciones"
android:textSize="30sp" />
</LinearLayout>
我不明白当单击一个甚至没有代码的按钮时,如何从另一个按钮启动代码。欢迎任何帮助。谢谢。
最佳答案
根据问题评论,发生的情况如下:
编译资源时,资源 XML 文件被编译为二进制 XML 格式,并在 R.java
中生成资源标识符。生成的标识符指向资源二进制文件中的特定项目。标识符只是序列中的整数,其值按照它们在资源 XML 文件中声明的顺序给出。
大多数时候这都可以正常工作。当您修改源 XML 文件时,所做的更改将编译到二进制资源和 R
类中。
但是,有时构建依赖系统无法正常工作。例如,R
中的标识符已更新,但并非所有二进制资源都反射(reflect)更改后的标识符。当您尝试在代码中通过 id 引用元素时,它实际上返回二进制资源中使用该 id 指定的其他一些元素。
在这种情况下,你很“幸运” - 层次结构中存在该 id 的 View (没有返回 null,也没有 NullPointerException
),而且它恰好是一个 Button
(没有ClassCastException
)。
清理项目会删除已编译的资源二进制文件和生成的 R.java
,因此重新编译时,它们会再次同步。
关于java - Button2 正在做 Button1 应该做的事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20693397/
我为我的一些问题设置了标签。当搜索 labels="ab"时,我得到了相关的标签,但我似乎找不到询问标签的正确语法!="ab"。如何查询不等于ab的? 最佳答案 != 对我有用,尽管它只显示带有标签的
我最近使用 Visual Studio 2013 Express 配置了 GITHUB 和 Demo GITHub 帐户,即用于练习目的。 Good News is that : I have con
我有一个用于播放和暂停的切换按钮。 这是代码: export default (props) => { let [soundState, setSoundState] = useState({ s
一个 XML 文件被发布到我的 spring mvc 正在响应的 URL。 在 .NET 中,我可以这样做: request.Form[0] request.Form["abc"] 或 request
我们的监控脚本遇到问题。 程序流程为 客户将文件(.csv 格式)ftp/sftp 到“源”目录 Bash 脚本将完成的 .csv 文件重命名为 .aaa 文件 另一个 Bash 脚本将“.aaa”文
如果我开始一个线程: new Thread(() -> { while (running) { try { Thread.sl
我正在制作一个看起来像真正的书的 PDF 阅读器。 我在 ScrollView 中有一个 UIImageView 作为书的背景(想象一本打开的书,有空页)。 UIImageView 的层有 2 个子层
创建 Accordion - 在幻灯片上 - 正在滑动的元素下方的元素似乎向下移动了 px,然后又向上移动,从而产生了颤动效果。 $(document).ready(function() { //Pr
我有一个非常奇怪的问题,但只有在运行 Ubuntu 时才会出现(在 CentOS 上一切正常)。我用 Perl 编写了一个脚本并使用了 Mail::IMAPClient模块。 当我运行以下命令时: p
我知道我可以检查 UITextView 是否正在使用 textViewDidBeginEditing: 进行编辑,但我想检查它是否正在使用 if 语句进行编辑? 最佳答案 使用方法isFirstRes
我正在制作一个简单的点击器类型的游戏。问题是,我的 JPanel 忽略了我设置为每秒更新的 Swing 计时器,而是每毫秒更新一次,即使我删除了计时器也是如此。除了计时器的监听器之外,不会在任何地方调
我有以下代码,应该通过组织列表对每个组织进行 td,对每个组织调用 toString 方法,并将结果打印到控制台和名为 Debug1.tab 的文件。 try { StreamWriter p
我有以下代码用于将文件从 url 下载到 sdcard 。此代码适用于小文件,但当文件大时,我下载的文件大小为 0。任何帮助将不胜感激。 Java 代码 setContentView(R.layout
我有一个必须使用 tomcat 部署的 Angular 项目。 Angular 文件在 dist/project-ui/ 中构建文件夹。我复制了 project-ui文件夹到 webapps tomc
我有一堆切换按钮,下面有标签。如果按钮的标签变得太长,那么下一行的第一个按钮将卡在该标签上。 这是我的代码: https://jsfiddle.net/Android272/c150305z/ 我查了
具有特殊字符的 InnerHTML 正在 trim 数据。 elem.innerHTML = displayedObjects.name; 这里的 displayedObjects.name 包含一个
我已经成功地设置了我的证书和 key ,并使用了在这里找到的 mysql 文档: http://dev.mysql.com/doc/refman/5.1/en/replication-solution
在为游戏制作动画和更新计时器时,我读到任何与 GUI 相关的 Activity 都应该在 EDT 上运行,包括重新绘制屏幕。我正在使用单个 ScheduledExecutorService 来更新和绘
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Large numbers erroneously rounded in Javascript 我正在使用
我已经为 .NET RyuJit 安装了新的 Jit 编译器,并按照安装文档中的说明在 regedit 的 .NetFramework 中设置了 AltJit=* 键。 http://blogs.ms
我是一名优秀的程序员,十分优秀!