Android 吐司未显示在按钮上单击
我有一个祝酒词,只要按下“提交”按钮,就会显示: 这是我的密码:Android 吐司未显示在按钮上单击,android,toast,Android,Toast,我有一个祝酒词,只要按下“提交”按钮,就会显示: 这是我的密码: @SuppressLint("ShowToast") public void ButtonOnClick(View view){ SharedPreferences sharedPref= getSharedPreferences("chaosautoreply", 0); SharedPreferences.Editor editor= sharedPref.edit();
@SuppressLint("ShowToast")
public void ButtonOnClick(View view){
SharedPreferences sharedPref= getSharedPreferences("chaosautoreply", 0);
SharedPreferences.Editor editor= sharedPref.edit();
TextView tvMessage = (TextView) findViewById(R.id.editMessage);
String message = tvMessage.getText().toString();
editor.putString("message", message).commit();
Toast.makeText(getApplicationContext(), "Updated Successfully", 10);
}
以下是我的布局:
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editMessage"
android:layout_centerHorizontal="true"
android:clickable="true"
android:onClick="ButtonOnClick"
android:text="Submit" />
没有要显示的错误或日志。submit似乎可以运行,但它不能Toast。您必须在Toast上调用show方法以使其显示内容
Toast.makeText(getApplicationContext(), "Updated Successfully", 10).show();
Toast.makeText(getApplicationContext(), "Updated Successfully", 10).show();
制作完面包片后,您需要在面包片上调用
show()
,否则它将永远无法显示。我很好奇,你为什么不发出警告;如果您只是听了Eclipse,您就会看到错误并能够自己纠正它 这是因为,您必须在Toast上调用show方法,使其显示如下内容:
Toast.makeText(getApplicationContext(), "Updated Successfully", 10).show();
我不知道我怎样才能抑制这个警告。我没有更改任何类似的设置。您的第一行
@SuppressLint(“ShowToast”)
将取消创建Toast时Eclipse通常会向您显示但不显示的警告。对于将看到此帖子的其他人getApplicationContext()
不推荐,请尝试使用YOUACTIVITY。此