我使用android 2.3.3 我的代码:
read=(Button)findViewById(R.id.bt_read);
write=(Button)findViewById(R.id.bt_write);
text=(EditText)findViewById(R.id.editText1);
// write file
write.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Write", Toast.LENGTH_SHORT);
}
});
但是当我点击按钮Toast not show。谁能告诉我为什么?感谢
答案 0 :(得分:1)
更改
Toast.makeText(getApplicationContext(), "Write", Toast.LENGTH_SHORT);
到
Toast.makeText(getApplicationContext(), "Write", Toast.LENGTH_SHORT).show();
答案 1 :(得分:1)
您必须添加show方法才能显示Toast View
Toast.makeText(getApplicationContext(), "Write", Toast.LENGTH_SHORT).show();
没有显示Toast,您的代码如下所示
Toast.makeText(getApplicationContext(), "Write", Toast.LENGTH_SHORT);
toast view有关详细信息,请参阅此文档http://developer.android.com/guide/topics/ui/notifiers/toasts.html
答案 2 :(得分:0)
在Toast结束时,您需要添加“.show()”。
代码:
Toast.makeText(getApplicationContext(), "Write", Toast.LENGTH_SHORT).show();