title: Onclicklistener moving to same activity in android
body: <p>Hi in my application I am displaying image with text by using grid view layout.In this i used list view and frame layout for designing a xml.</p>
  
  <p>In that i used 6 items named as about us,photo gallery etc
  Now My problem is if i click the about us i want to move to about us activity and if i click the photo gallery it will move to flickr activity class.</p>
  
  <p>But if i click the any activity it's moving to same activity.Now i don't want like that i want to move to particular activity </p>
  
  <p><strong>MainActivity class</strong></p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener
  {
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main1);
          final int pos = getIntent().getIntExtra("pos",0); 
          GridView gridView = (GridView)findViewById(R.id.gridview);
          gridView.setAdapter(new MyAdapter(this));
          gridView.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; a, View v, int position,
                      long id) {
                  //Grab the item position here and write further code
                   switch (pos) {
                   case 0:
                       Intent nextScreen = new Intent(getApplicationContext(), Aboutus.class);
                      startActivity(nextScreen);
                       break;
                   case 1:
                       Intent nextScreen1 = new Intent(getApplicationContext(), FlickrActivity.class);
                      startActivity(nextScreen1);
                       break;
  
  
              }
              }
  
          });
      }
  
      private class MyAdapter extends BaseAdapter
      {
          private List&lt;Item&gt; items = new ArrayList&lt;Item&gt;();
          private LayoutInflater inflater;
  
          public MyAdapter(Context context)
          {
              inflater = LayoutInflater.from(context);
  
              items.add(new Item("About Us", R.drawable.aboutus));
              items.add(new Item("Photo Gallery", R.drawable.photo));
              items.add(new Item("Veg Food", R.drawable.veg));
              items.add(new Item("Non Veg Food", R.drawable.nonveg));
              items.add(new Item("Location", R.drawable.contactus));
              items.add(new Item("Contact Us", R.drawable.contactus));
  
          }
  
          @Override
          public int getCount() {
              return items.size();
          }
  
          @Override
          public Object getItem(int i)
          {
              return items.get(i);
          }
  
          @Override
          public long getItemId(int i)
          {
              return items.get(i).drawableId;
          }
  
          @Override
          public View getView(int i, View view, ViewGroup viewGroup)
          {
              View v = view;
              ImageView picture;
              TextView name;
  
              if(v == null)
              {
                 v = inflater.inflate(R.layout.gridview_item, viewGroup, false);
                 v.setTag(R.id.picture, v.findViewById(R.id.picture));
                 v.setTag(R.id.text, v.findViewById(R.id.text));
              }
  
              picture = (ImageView)v.getTag(R.id.picture);
              name = (TextView)v.getTag(R.id.text);
  
              Item item = (Item)getItem(i);
  
              picture.setImageResource(item.drawableId);
              name.setText(item.name);
  
              return v;
          }
  
          private class Item
          {
              final String name;
              final int drawableId;
  
              Item(String name, int drawableId)
              {
                  this.name = name;
                  this.drawableId = drawableId;
              }
          }
      }
  
      @Override
      public void onClick(DialogInterface dialog, int which) {
          // TODO Auto-generated method stub
  
      }
  
  }
  </code></pre>