android-toast

Kill android toast?

限于喜欢 提交于 2019-12-11 11:28:40
问题 I have a button and on button click toast appears, if the user clicks on button several times and go to previous activity or even close the aplication toast is still visible, How to finish or cancel the toast when user goes to any other activity or how to prevent generation of toast? Toast.makeText(getApplicationContext(), "Enter correct goal!", Toast.LENGTH_SHORT).show() 回答1: try this cancel() Toast by using handler Toast toast = Toast.makeText(getApplicationContext(), "Test", Toast.LENGTH

Is it possible to create a clickable Toast-like notification?

孤人 提交于 2019-12-11 02:44:28
问题 I have a need to show a minimally-intrusive non-blocking notification which is not tied to the activity it was shown in (like a Toast ) and which is clickable. Anyone have any idea whether or not this is possible? Unfortunately it appears Toast notifications (custom or otherwise) are not clickable (i.e. setting an OnClickListener on its views has no effect). And, correct me if I'm wrong, all the alternatives ( AlertDialg , PopupWindow , Crouton ) show a notification which is tied to the

Raising a toast when Power Button is pressed twice

北战南征 提交于 2019-12-11 02:03:34
问题 What i am trying to do is ,double clicking the power button will raise a toast "Sending Message", doesn't matter if screen is On or Off.What i have done is , i have recorded the time duration of the clicks on power button & If the difference b/w the current click and previous click duration is less than a 1sec, then it will raise the toast. But its raising the toast on the single click also. Please Help me out 1.MainActivity.java public class MainActivity extends Activity { @Override public

Custom DatePicker On EditText

我只是一个虾纸丫 提交于 2019-12-11 01:51:50
问题 I have 2 EditText . When anyone click on a EditText datepicker is displayed to set date in EditText . so my coding for EditText is sdate.setOnTouchListener( new DrawableClickListener.RightDrawableClickListener(sdate) { @Override public boolean onDrawableClick() { MyDatePickerDialog(sdate);// put edit text view. return true; } } ); edate.setOnTouchListener( new DrawableClickListener.RightDrawableClickListener(edate) { @Override public boolean onDrawableClick() { MyDatePickerDialog(edate);//

Xamarin Toast Message error (C#)

帅比萌擦擦* 提交于 2019-12-10 19:57:39
问题 I want to display a toast Message. If I'd do this in onCreate() it'd work fine. But I want to do it like this and I get an error: Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference What should I do? public void textToast(string textToDisplay) { Toast.MakeText(this, textToDisplay, ToastLength.Long).Show(); } class SampleTabFragment : Fragment { Button add; MainActivity main = new

How to only allow certain values as parameter for a method in Java?

强颜欢笑 提交于 2019-12-08 17:00:45
问题 I want to write a method that only takes certain values for a parameter, like f.e. in the Toast class in Android. You can only use Toast.LENGTH_SHORT or Toast.LENGTH_LONG as duration for the method makeText(Context context, int resId, int duration) . I had a look at the source code of the Toast class but found nothing there. How can I achieve that? 回答1: Use an Enum Type, from the Java Tutorial, An enum type is a special data type that enables for a variable to be a set of predefined constants

Toast: Difference between “this” and “getApplicationContext()”?

假如想象 提交于 2019-12-08 16:03:24
问题 My device runs Android 5.1.1 and I found out that if I use Toast.makeText(this, "This is a toast", Toast.LENGTH_SHORT).show(); I got this: But if I use getApplicationContext() instead of this , Toast.makeText(getApplicationContext(), "This is a toast", Toast.LENGTH_SHORT).show(); I got this: Both are called directly from the activity. Why is this? 回答1: It has to do with the Theme the Context has associated with it. Using this is using a context (I'm assuming your Activity or Fragment ) that

custom Toast at screen top

强颜欢笑 提交于 2019-12-07 03:05:45
问题 Please read the question before answering with your standard routine to print a Toast :) I'd like to display a Custom Toast at the top left corner of the screen. I use this code to create the Toast: Toast mFixedToast = new Toast(getApplicationContext()); mFixedToast.setDuration(timeout); mFixedToast.setView(myInflatedLayout); mFixedToast.setGravity(Gravity.TOP|Gravity.FILL_HORIZONTAL, 0, 0); mFixedToast.setMargins(0,0); However, in some devices , for example Samsung Galaxy S4, the toast is

Toast message not shown

限于喜欢 提交于 2019-12-06 10:13:21
问题 I am trying to show a toast message in my application using the following code. AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Do you want to continue?"); alert.setPositiveButton("Continue", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try{ //This code generates an Activity Not Found exception } catch(ActivityNotFoundException e) { System.out.println("Activity Not Found Exception Raised"); Toast.makeText

Display two Toast messages at once?

落花浮王杯 提交于 2019-12-05 05:16:44
I would like one Toast message to display in one location and a different Toast message to display in another location simultaneously. Multiple Toast messages seem to always queue and display in order. Is it possible to show both messages at the same time? Is there a workaround that at least gives that appearance and doesn't involve messing with the activity layout? Edit: It seems the answer to the first question is no, it's not possible. How about a workaround? A solution for me would include something that appears "over" the app like a Toast and doesn't interfere with user interaction with