When I type code like this in MainActivity:-
Button btn=(Button) findViewById(R.id.mainButton1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View p1)
{
Toast.makeText(this,"Some text...",Toast.LENGTH_SHORT).show();
}
});
It shows the error
There is no applicable method to '(com.example.MainActivity.(anonymous),java.lang.String,int)'
but
Button btn=(Button) findViewById(R.id.mainButton1);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View p1)
{
Toast.makeText(MainActivity.this,"Some text...",Toast.LENGTH_SHORT).show();
}
});
This not shows the error,
So is any difference present in MainActivity.this
and this
please vote to delete this post because nothing is useful in this post for future readers. All information is given in duplicate question