Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5843669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:11:11+00:00 2026-05-22T12:11:11+00:00

Just a beginner at Android development. I’ve currently got a GridView setup to act

  • 0

Just a beginner at Android development. I’ve currently got a GridView setup to act as a main menu for my application. I’ve managed to get an intent working using OnItemClickListener(). However all 6 of my images when clicked go to the same Activity class. How do I go about giving each image an intent to different activities?

MainActivity:

public void onCreate(Bundle savedInstanceState)
{
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);

   GridView gridview = (GridView) findViewById(R.id.gridview);
   gridview.setAdapter(new ImageAdapter(this));
   gridview.setOnItemClickListener(new OnItemClickListener() {

       public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
           Toast.makeText(nclApp2.this, "" + position, Toast.LENGTH_SHORT).show();
           Intent i = new Intent(nclApp2.this, Screen2.class);

           startActivity(i);
       }
   });

ImageAdapter:

public class ImageAdapter extends BaseAdapter {
private Context mContext;

public ImageAdapter(Context c) {
    mContext = c;
}

public int getCount() {
    return mThumbIds.length;
}

public Object getItem(int position) {
    return null;
}

public long getItemId(int position) {
    return 0;
}

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8, 8, 8, 8);
    } else {
        imageView = (ImageView) convertView;
    }

    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}

// references to our images
private Integer[] mThumbIds = {
        R.drawable.icon, R.drawable.icon,
        R.drawable.icon, R.drawable.icon,
        R.drawable.icon, R.drawable.icon,

};

class MyOnClickListener implements OnClickListener
{
 private final int position;

 public MyOnClickListener(int position)
 {
  this.position = position;
 }

 public void onClick(View v)
 {

 }
}

Edit: After hours searching, I found that this works!:

public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
           Toast.makeText(nclApp2.this, "" + position, Toast.LENGTH_SHORT).show();
           //Intent i = new Intent(nclApp2.this, Screen2.class);

           Intent myIntent = null;
           if(position == 0){
               myIntent = new Intent(v.getContext(), Screen1.class);
           }
           if(position == 1){
               myIntent = new Intent(v.getContext(), Screen2.class);
           }
           if(position ==2){
               myIntent = new Intent(v.getContext(), Screen3.class);
           }
           startActivity(myIntent);
       }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:11:12+00:00Added an answer on May 22, 2026 at 12:11 pm

    You have

    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    

    so make use of the int position part of it…

    switch (position) {
    case 0:
    // start one activity
    break;
    case 1:
    // start another activity
    break;
    // etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just a beginner in the application development industry. I know the accelerometer
I am beginner in android, I just want to know how to get the
I'm just starting to get into jquery/javascript programming so this may be a beginner
I'm just a beginner in SQL Server database development and was wondering which authentication
I am just a beginner in i-phone development and right now i am developing
First off I am a beginner in Android development; I have been doing a
Im brand new to Android Application development and I am working on an application
i am just beginner of iphone programming . i want to get size(full size)
I am a web application developer, just a beginner. I am designing a small
I am a beginner in Android development, and I have to continue a project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.