smallseo.info

Toast

An Objective-C category that adds toast notifications to the UIView object class.

What is the value of Toast.LENGTH_LONG and Toast.LENGTH_SHORT?

I am printing Toast message in my application to show notification but i want to know value of Toast.LENGTH_LONG and Toast.LENGTH_SHORT. What other values i can use.

Can anyone tell me what is the value of these two variables?


Source: (StackOverflow)

Center text in a toast in Android

I was wondering if there was a way to display all text in a toast to be centered. For instance, I have a toast that has 2 lines of text in it. For purely aesthetic reasons, I would like the text to center-aligned instead of left-aligned. I've looked through the documentation and can't find anything about it. Is there a simple way to do this that I have missed?

Thanks Chris


Source: (StackOverflow)

Custom toast in android : a simple example

I'm new to android programming.Can any one give me a simple example showing a custom toast notification in android?


Source: (StackOverflow)

Can an Android Toast be longer than "Toast.LENGTH_LONG"?

When using setDuration for a Toast is it possible to set a custom length or at least something longer than Toast.LENGTH_LONG?


Source: (StackOverflow)

How to change position of Toast in Android?

When I use Toast to display some popup text on the screen, it displays the text a little bit above the bottom of the screen, which is the default position.

Now I want to display it in the middle of screen or somewhere according to my choice.

Can anyone guide me how to achieve this?


Source: (StackOverflow)

Finish activity after toast message disappears?

Does anybody know, if there is a possibility to do something (in my case finish activity) on toast message will be closed?


Source: (StackOverflow)

getting context in AsyncTask

I am trying to get the context in my AsyncTask of the class called Opciones(this class is the only one that call that task) but I don't know how to do it, I saw some code like this:

      protected void onPostExecute(Long result) {

    Toast.makeText(Opciones.this,"Subiendo la foto. ¡Tras ser moderada empezara a ser votada!: ", Toast.LENGTH_LONG).show(); 
}

But it doesn't work for me it says: "No enclosing instance of the type Opciones in scope"


Source: (StackOverflow)

Android: How to set the colour of a Toast's text

I am displaying a toast message as the result of an if statement using the following code:

Toast.makeText(getBaseContext(), "Please Enter Price", Toast.LENGTH_SHORT).show();

It is displayed as white text on a white background, as such it can not be read! My question is, how can I change the colour of the toast's text?


Source: (StackOverflow)

Use Toast inside Fragment

I'm trying to show a Toast Message when user click on a Button inside a Fragment. The problem is I cannot access the activity to show the Toast on it.

Here's the source of Fragment:

    public class FrgTimes extends Fragment
    {
        ScrollView sv;
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) 
        {
            if (container == null) { return null; }

            sv = (ScrollView)inflater.inflate(R.layout.frg_times, container, false);

            btnTime1.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

            //******  HERE's the PROBLEM  ********
            Toast.makeText(<The Activity>, "Please long press the key", Toast.LENGTH_LONG );

            }});

            return sv;
        }

and Here's what I've been tried.

Toast.makeText( getActivity()  , ...
Toast.makeText( getView().getContext()  , ...
Toast.makeText( getActivity().getApplicationContext()  , ...
Toast.makeText( sv.getContext()  , ...
Toast.makeText( sv.getRootView().getContext()  , ...

In Debug I can see that all of these codes run without any exception but no TOAST being displayed.


Source: (StackOverflow)

Popup over incoming-call screen

I want to create a customized popup over the android's incoming call screen where I wish to add information for the user. I want the popup to not disable any clickability from the background so that the user could still answer the call.

I know it is possible since many applications do it, e.g. MeZeZe app: enter image description here

Some more information:

  1. A translucent theme did not work since it cancels the former activity's clickability.
  2. A toast is not an option - I don't want it to disappear.
  3. I know there are many similar threads - I read many of them and none answer my specific problem.
  4. I already know how to "make something happen" once a call is receiver, so no need for INCOMING_CALL activity tips.

Would appreciate any help! Thanks


Source: (StackOverflow)

java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare();

I have an Android app running a thread. I want a Toast message to show with a message.

When I do this, I get the below exception:

Logcat trace:

FATAL EXCEPTION: Timer-0 
 java.lang.RuntimeException: Can't create handler inside thread that has not 
    called Looper.prepare()

 at android.os.Handler.<init>(Handler.java:121)
 at android.widget.Toast$TN.<init>(Toast.java:322)
 at android.widget.Toast.<init>(Toast.java:91)
 at android.widget.Toast.makeText(Toast.java:238) 

Is there a work around for pushing Toast messages from threads to the User Interface?


Source: (StackOverflow)

What is the android.widget.Toast equivalent for iOS applications?

I have made Android application a few months ago. The Toast class is very useful for me. I do not need to consider the main Thread and place to show it. Anywhere I can show it and just leave that and it is automatically disappeared.

Toast.makeToast(context, msg, Toast.LENGTH_SHORT).show();

That's it. ^^

What about iPhone? Is there something like the Toast? Just show message and do not need to care about it. It will be automatically disappeared.


Source: (StackOverflow)

Why are Android popup messages called toasts? [closed]

My guess it that the lightweight notifications in Android are called Toast because they popup like toast from a toaster. Can anyone confirm this or provide a better explanation? I am teaching a course on Android development and would like to edit the wiki, so I want to be sure to get it right.


Source: (StackOverflow)

Error due to invalid combination of Toast and OnClickListener

I'm trying to use Toast inside OnCLickListener. My code triggers the following error:

The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new View.OnClickListener(){}, String, int)

This is my code:

    Button register = (Button) findViewById(R.id.register);
    register.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            EditText name = (EditText)findViewById(R.id.name);
            String Lname = name.getText().toString();

            Toast.makeText(this, Lname, Toast.LENGTH_SHORT).show();



        }
    });

Source: (StackOverflow)