Reputation: 1120
I have a toast that should display anytime my "submit" button is pressed:
Here is my code:
@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);
}
Here is my layout:
<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" />
There are no errors or logcats to display. The submit appears to function, but it doesn't Toast.
Upvotes: 0
Views: 122
Reputation: 5152
its because, You have to call the show method on Toast to make it display something like:
Toast.makeText(getApplicationContext(), "Updated Successfully", 10).show();
Upvotes: 4
Reputation: 4136
You need to call show()
on the Toast after making it, otherwise it will never be displayed. I'm curious as to why you suppressed the warnings for this; if you had simply listened to Eclipse, you would have seen the error and been able to correct it yourself.
Upvotes: 2
Reputation: 2595
You have to call the show method on Toast to make it display something
Toast.makeText(getApplicationContext(), "Updated Successfully", 10).show();
Upvotes: 4
Reputation: 4522
Toast.makeText(getApplicationContext(), "Updated Successfully", 10).show();
Upvotes: 5