package com.example.sumant.myapplication2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout myLayout=new RelativeLayout(this);
Button myButton =new Button(this);
myLayout.addView(myButton);
setContentView(myLayout);
}
}
The "this" variable is as a reference for the current object. But I am not getting as to why it has been used as a parameter in the above piece of code. I am able to decipher that maybe the constructor of RelativeLayout
class might be parameterized and we are passing it an object of the same class to initialize the RelativeLayout
object. Can someone please elaborate it to me.