Question: I'm new to this site so hopefully I'm phrasing my question correctly. 

I'm working through some introductory Android programming. What allows me to call the `Toast.makeText` method, but I cannot do the same for the `setGravity` method immediately after? Why can I reference the first non-static method, but not the next? I'm also new to using anonymous inner classes. 

```
mTrueButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Toast.makeText(quizActivity.this, R.string.correct_toast, Toast.LENGTH_SHORT.show();
        Toast.setGravity(0, 0 ,0);
    }
});

```

Answer: 
You have to create Toast class object

```
public void ShowToast(String message){

    Toast t = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG);

    OR

    // Toast t = new Toast(getContext());  if custom view require
    t.setDuration(Toast.LENGTH_LONG);
    t.setText(message);

    t.setGravity(Gravity.RIGHT,0,0);
    t.show();

}

```
Static methods can be accessed by using their class name. Like: `Classname.staticMethod();`

So, here in `Toast` class, we have `makeText()` method and `setGravity()` method. But `makeText()` method is a static method. So, we can access it by their class name. Just like below:

```
Toast.makeText()

```

But `setGravity()` method is not a static method. So, we can't call it by using their class name.

If you have to call `setGravity()` method then you have to create an object of `Toast` class.

```
Toast t = new Toast(getContext());  
t.setDuration(Toast.LENGTH_SHORT);
t.setText(message);
t.setGravity(Gravity.CENTER, 0, 0);
t.show();

```