Grid view image link to activites
<p>I have hit a brick wall, a tutorial i have followed simply enlarges the images on click.</p>

<p>what i want to do is for each image it opens a different activity. </p>

<p>eg the algebra image open the algebraactivity, decimal image on click opens decimal activity etc.</p>

<p>this is probably simple, but it is not very obvious to me at the moment.</p>

<p>Here is the main activity.</p>

<pre><code>import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.GridView;  
public class MathsSubjectsActivity extends Activity {   

 // Keep all Images in array
 public Integer[] mThumbIds = {        
R.drawable.algebraicon,R.drawable.coordsicon,         
R.drawable.decimalsicon,R.drawable.fractionsicon,  
R.drawable.algebraicon,R.drawable.algebraicon,
R.drawable.powersicon,R.drawable.algebraicon,        
R.drawable.coordsicon,R.drawable.algebraicon, 
}; 


@Override    
public void onCreate(Bundle savedInstanceState) {     
super.onCreate(savedInstanceState);     
setContentView(R.layout.subjects);  
GridView gridView = (GridView) findViewById(R.id.grid_view); 
 // Instance of ImageAdapter Class   

gridView.setAdapter(new ImageAdapter(this,mThumbIds)); 
 /**      * On Click event for Single Gridview Item      * */  

gridView.setOnItemClickListener(new OnItemClickListener() {  

@Override         
public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {            
switch(position)             
   {   
   case 0:
       Intent login = new Intent(getApplicationContext(), MathsAlgebraActivity.class);
       login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
       startActivity(login);
       break;
       case 1:
       Intent coords = new Intent(getApplicationContext(), MathsMultiActivity.class);
       coords.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
       startActivity(coords);
       break;
       case 2:
       Intent decim = new Intent(getApplicationContext(), MathsMultiActivity.class);
       decim.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
       startActivity(decim);
       break;
   //and so on for other activities.  
    default:
    break;                             

    } 


    }     
    }); 
    }   

    } 
</code></pre>

<p>Below is the image adapter which handles the images.</p>

<pre><code>  import android.content.Context;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;

  private Context mContext;      
  private Integer[] resIds; 

  //Constructor 
  public ImageAdapter(Context c,Integer[] resIds){ 
  mContext = c;    
  this.resIds=resIds;
  }    
  @Override                    

  public int getCount() {  
  return resIds.length;                  
  }         
  @Override                   

  public Object getItem(int position) {   
                  return resIds[position];                     }     
  @Override                  
  public long getItemId(int position) {    
                 return 0;                  
  }                                    

  @Override            
     public View getView(int position, View convertView, ViewGroup parent) {                                
     ImageView imageView = new ImageView(mContext); 
     imageView.setImageResource(resIds[position]);  
     imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);   
     imageView.setLayoutParams(new GridView.LayoutParams(70, 70)); 
    return imageView;                    
    }                                 
    }   
</code></pre>

<p>can run case 0 but not 1 or 2.</p>

<p>errors from log: </p>

<pre><code>    Thread [&lt;1&gt; main] (Suspended (exception ActivityNotFoundException)) 
Instrumentation.checkStartActivityResult(int, Object) line: 1405    
Instrumentation.execStartActivity(Context, IBinder, IBinder, Activity, Intent, int) line: 1379  
MathsSubjectsActivity(Activity).startActivityForResult(Intent, int) line: 2827  
MathsSubjectsActivity(Activity).startActivity(Intent) line: 2933    
MathsSubjectsActivity$1.onItemClick(AdapterView, View, int, long) line: 51  
GridView(AdapterView).performItemClick(View, int, long) line: 284   
AbsListView$PerformClick.run() line: 1812   
ViewRoot(Handler).handleCallback(Message) line: 587 
ViewRoot(Handler).dispatchMessage(Message) line: 92 
Looper.loop() line: 130 
ActivityThread.main(String[]) line: 3683    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line:     not available [native method]  
Method.invoke(Object, Object...) line: 507  
ZygoteInit$MethodAndArgsCaller.run() line: 839  
ZygoteInit.main(String[]) line: 597 
NativeStart.main(String[]) line: not available [native method]  
</code></pre>
