Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package com.example.tutorial;
  2.  
  3. import android.content.Context;
  4. import android.view.LayoutInflater;
  5. import android.view.View;
  6. import android.widget.RelativeLayout;
  7. import android.widget.TextView;
  8.  
  9. /**
  10.  * Created by Shiburagi on 26-Jan-15.
  11.  */
  12. public class MainLayout extends RelativeLayout{
  13.  
  14.     /**
  15.      * Constructor
  16.      * @param context
  17.      */
  18.     public MainLayout(Context context) {
  19.         super(context);
  20.  
  21.         // call init function
  22.         init(context);
  23.     }
  24.  
  25.     public MainLayout(Context context, LayoutInflater inflater){
  26.         super(context);
  27.         // call init function
  28.         init(context);
  29.  
  30.         // call and receive view from the activity_main.xml
  31.         View view = inflater.inflate(R.layout.activity_main, null);
  32.  
  33.         // add the view into layout
  34.         addView(view);
  35.     }
  36.  
  37.     /**
  38.      * to initialize component been used in the application
  39.      * @param context
  40.      */
  41.     private void init(Context context ){
  42.  
  43.         // declare textview component
  44.         TextView textView=new TextView(context);
  45.  
  46.         // set value of the textview.
  47.         textView.setText("Hello World!");
  48.  
  49.         // add textview into this layout
  50.         addView(textView);
  51.  
  52.     }
  53. }