How to start activity from multiple items in GridView
<p>This is my MainActivity class</p>

<pre><code>public class MainActivity extends AppCompatActivity {

    GridView gridView;
    Context context;
    ArrayList prgmName;
    public static String [] prgmNameList={"GFU","FAB","DRAW","ANIM","ABC","DEF","PHH","XSE","HGY"};
    public static int [] prgmImages={R.drawable.sample_0,R.drawable.sample_1,R.drawable.sample_2,R.drawable.sample_3,R.drawable.sample_4,R.drawable.sample_5,R.drawable.sample_6,R.drawable.sample_7,R.drawable.sample_0};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Custom Example for GridView ...
        gridView = (GridView) findViewById(R.id.gridView1);
        gridView.setAdapter(new GridCustomAdapter(this, prgmNameList,prgmImages));




        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
               // displayView(0);
                /*Intent intent = null;
                if (position == 0){
                    intent = new Intent(view.getContext(), ToolbarExample.class);
                }
                if (position == 1){
                    intent = new Intent(view.getContext(), FloatingButtonExample.class);
                }
                startActivity(intent);*/

                switch (position) {
                    case 0:
                        Intent i = new Intent(getApplicationContext(), ToolbarExample.class);
                        i.putExtra("id", position);
                        startActivity(i);
                        break;

                    case 1:
                        Intent j = new Intent(getApplicationContext(), FloatingButtonExample.class);
                        j.putExtra("id", position);
                        startActivity(j);
                        break;
                    case 2:

                        break;
                    case 3:

                        break;
                    default:
                        break;
                }

            }
        });
    }
}
</code></pre>

<p>And my Adapter class as follows : I want to start multiple activities from adapter class but it's not working</p>

<pre><code>public class GridCustomAdapter extends BaseAdapter {

    String [] result;
    Context context;
    int [] imageId;

    private static LayoutInflater inflater=null;
    public GridCustomAdapter(MainActivity mainActivity, String[] prgmNameList, int[] prgmImages) {
        // TODO Auto-generated constructor stub
        result=prgmNameList;
        context=mainActivity;
        imageId=prgmImages;
        inflater = (LayoutInflater)context.
                getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return result.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public class Holder
    {
        TextView tv;
        ImageView img;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        Holder holder=new Holder();
        View rowView;

        rowView = inflater.inflate(R.layout.custom_grid_items, null);
        holder.tv=(TextView) rowView.findViewById(R.id.textView1);
        holder.img=(ImageView) rowView.findViewById(R.id.imageView1);

        holder.tv.setText(result[position]);
        holder.img.setImageResource(imageId[position]);

        rowView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
               /* Intent intent = new Intent(context, ToolbarExample.class);
                context.startActivity(intent);*/

                Toast.makeText(context, "You Clicked "+result[position], Toast.LENGTH_SHORT).show();
            }
        });

        return rowView;
    }
}
</code></pre>