android 测试应用程序..toast 不起作用

标签 android

我是 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/

相关文章:

android - CWAC 摄像头是否捕获用户的 GPS 位置?

android - 如何在没有新 Intent 的情况下清除 Activity 堆栈

android - 如何在 android 的单独线程中更新谷歌地图标记位置

android - 更改不确定水平进度条的背景颜色

android - 使用 CollapsingToolbarLayout 的错误行为 SwipeRefreshLayout

安卓游戏 - 记录时间

java - edittext 声明为 final,settext 不工作

android - 为什么我们需要使用 android 工具链(或 NDK)来编译在 android 应用程序上下文中运行的 c/c++ 代码?

android - setScaleCenter() 在缩小 Sprite 时导致问题 - AndEngine

android:将内部存储中的文件公开保存在目录中