我是 android 的新手,正在尝试创建一个小应用程序。
我的java文件:
//creating object for imagebutton class
ImageButton mainButton = (ImageButton) findViewById(R.id.imageButtonone);
//creating onclick listener
mainButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//show message
Toast toast = Toast.makeText(SkeletonActivity.this, "Button Pressed", Toast.LENGTH_LONG);
toast.show();
}
});
XML:
<ImageButton android:id="@+id/imageButtonone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/dog8" />
其中 imageButton 的 id = imageButtonone。
我无法打印“按下按钮”。 请帮忙!
最佳答案
1) 也许您的代码没有到达 onClick 方法。检查您的 mainButton 是否为 null。
2) 在eclipse菜单中:project->clean(你的项目)
关于android 测试应用程序..toast 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8291927/