I
I
Ivan Bogomolov2014-04-25 07:29:25
Java
Ivan Bogomolov, 2014-04-25 07:29:25

Calling a method in java. What's the difference between this.method() and method() when called inside a class?

There is a method inside the class.

public class RssReaderActivity extends Activity {
private void crossfade()
    {
        myButton.animate().alpha(1f).setDuration(animationShortDuration).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                step3Button.setVisibility(View.VISIBLE);
            }
        });
    }

There is a handler inside the same class:
...
private View.OnClickListener sayHelloClickedListener = new View.OnClickListener(){
          public void onClick(View v){
              Integer viewId = (Integer)v.getId();
              Resources viewRes = (Resources)v.getResources();
              String buttonIdent = (String) viewRes.getResourceEntryName(viewId);
              Log.v("OnClickLogger",buttonIdent);

              if( buttonIdent.equals(String.valueOf("button_sayHello")) ) {
                  sayHelloText = (TextView) findViewById(R.id.textView_sayHello);
                  sayHelloText.setText("Hello Man!");
              }

              if( buttonIdent.equals(String.valueOf("button_appStep2")) ){
                 crossfade(); /* понимаю что здесь нельзя использовать this */
              }
          }
    };

Is there a way to define this globally?
How correct is the use of calling the crossfade() method?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mrstrictly, 2014-04-25
@kraso4niy

Java allows you to use class methods from an inner class. If for some reason you want to explicitly specify the object of the called method, for example, in case of a name conflict, you can get a pointer to the container from the inner class by explicitly specifying the name of the container. In your case "RssReaderActivity.this.crossfade()".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question