У меня есть тост, который должен отображаться в любое время мой «отправить» кнопка нажата:Тост не показывая onButtonClick
Вот мой код:
@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 работает, но это не тост.
для тех, кто будет видеть этот пост 'getApplicationContext()' не рекомендуется, попробуйте использовать 'YOUACTIVITY .this' –