  package com.example.ghomi.chapter4_6;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.View;
  import android.widget.TextView;
  import android.widget.Toast;
  import android.widget.GridView;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  //public class MainActivity extends AppCompatActivity {
  public class MainActivity extends Activity {
       GridView gridView;
      // This Data show in grid ( Used by adapter )
       static final String[ ] GRID_DATA = new String[] {
            "Windows" ,
            "iOS",
            "Android" ,
            "Blackberry",
            "Java" ,
            "JQuery",
            "Phonegap",
            "SQLite",
            "Thread" ,
            "Video"
    };

  @Override
  public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView( R.layout.activity_main );
            // Get gridView object from xml file
            gridView = (GridView) findViewById(R.id.gridData);
            // Set custom adapter (GridAdapter) to gridView
            gridView.setAdapter(  new CustomGridAdapter( this, GRID_DATA ) );
            gridView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v,
                       int position, long id) {
                       Toast.makeText(
                            getApplicationContext(),
                            ((TextView) v.findViewById( R.id.grid_item_label ))
                            .getText(), Toast.LENGTH_SHORT).show();
                  }
           });
         }
 }