OpenSearch的()在Android的入门应用程序没有定义 [英] openSearch() in Android beginners app not defined

查看:111
本文介绍了OpenSearch的()在Android的入门应用程序没有定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始在Android初学者tutotial,我现在面对的问题。在在响应动作按钮这个页面它告诉我定义switch语句的一些调用OpenSearch的()的选项,openSettings()方法。然而,这些方法都没有定义(废话),它因此给我一个错误。

I'm just started the Android beginners tutotial and I now face a problem. On this page under "Respond to Action Buttons" it tells me to define a switch statement with some of the options calling the openSearch() and openSettings() methods. These methods however, are not defined yet (duh) which thus gives me an error.

本教程并没有说什么然而,有关如何定义它们。谁能给我介绍什么是指针,我应该在哪里定义帖的方法呢?如果他们是在同一个文件,如果是的话,他们应包含哪些内容?

The tutorial doesn't say anything however, about how to define them. Can anybody give me a pointer on what and where I should define thess methods? Should they be in the same file, and if so, what should they contain?

有什么建议,欢迎!

推荐答案

这些方法只是例子,谷歌提出的向您展示了如何使用switch语句。你可以把你想在那里什么,但我认为这一点是从一个switch语句进行,而不是把一个函数code在声明函数调用,以保持code干净。该功能可能会在以某种方式同.java文件中声明像

These methods are just examples that Google put in to show how you would use a switch statement. You can put anything you want in there, but I think the point is to make function calls from a switch statement, instead of putting the code of a function in the statement, to keep code clean. The functions would probably be declared in the same .java file in some fashion like

private void openSearch() {
    // start or show the search activity/fragment
}

他们可以在技术上包含你希望他们什么,这取决于你想要的操作栏按钮做的事。如果你只是想看到的按钮,则可以飞溅Toast通知,看东西出现

They can technically contain anything you want them to, depending on what you want the action bar button to do. If you simply want to see that the buttons work, you can splash a Toast notification to see something appear

private void openSearch() {
    Toast.makeText(this, "Search button pressed", Toast.LENGTH_SHORT).show();
}

您将不得不导入吐司包,它可以通过完成按Ctrl + Shift + O 。 (或的Cmd + Shift + O 适用于Mac)

You'll have to import the Toast package which can be done by Ctrl+Shift+O. (Or Cmd+Shift+O for Mac)

希望这有助于清理混乱。享受学习的Andr​​oid!

Hope this helps clear up confusion. Enjoy learning Android!

这篇关于OpenSearch的()在Android的入门应用程序没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆