0

我对 Android 开发完全陌生,最近我购买了 Lynda.com Android 应用程序开发视频学习课程。

我面临以下问题:

  1. 创建了新项目
  2. 仅使用文本字段创建新的 xml 文件
  3. 然后转到 Main.xml(由默认创建的)并用按钮替换默认文本字段。
  4. 然后转到 Main.Java 并尝试通过代码“Button b = (Button) findViewById(android.R.id.button1);”调用添加的按钮
  5. 之后我尝试通过“b.”调用 setOnClickListner 函数,但没有名称为 setOnClickListner 的选项。

我按照视频中导师所说的确切步骤进行操作。我正在使用 Android SDK 12、Eclipse Indigo 并在 Gingerbread 2.3.3 上工作。在这方面的任何解决方案将不胜感激

4

1 回答 1

0

Possible situations:

  • Make sure you imported android.widget.Button
  • "Button b = (Button) findViewById(android.R.id.button1);"

Usually it is called:

"Button b = (Button) findViewById(R.id.button1);"

if you have defined the button correctly in the main.xml file. Also make sure you are not importing android.R

  • I suppose it is a typo but it is actually written setOnClickListener()

Cheers

于 2011-07-31T17:57:33.760 回答