开发者

setOnClickListner

I am totally new to Android development , recently i bought Lynda.com Android App Development video learning course.

I am facing following problem:

  1. Created new project
  2. Created new xml file with text field only
  3. Then go to Main.xml(that was created by defualt) and replace the default text field with button.
  4. Then go to Main.Java and try calling added button by code "Button b = (Button) findVie开发者_StackOverflow社区wById(android.R.id.button1);"
  5. After that I tried to call the setOnClickListner function by " b. " but there is no option with name of setOnClickListner.

I follow the exact steps as told by tutor in videos .. I am using Android SDK 12 ,Eclipse Indigo and working on Gingerbread 2.3.3. Any solution in this regard would be appreciated


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜