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

  • Home
  • SEARCH
  • 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 6137315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:42:37+00:00 2026-05-23T17:42:37+00:00

Hello i am making grid menu for activity , all things are working well

  • 0

Hello i am making grid menu for activity , all things are working well , when i click on specific image its show its position no like 0 1 . The problem is when i click on specfic image it should open the other intent , its not giving any error nor opening the other intent . kindly guide

public class Mood extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.mood);

        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)  {
                 switch (position) {
                 case 0:     
                    Intent intent = new Intent(v.getContext(),a.class);
                      startActivity(intent);
                 break;

                 case 1:     
                    Intent intent4 = new Intent(v.getContext(),b.class);
                      startActivity(intent4);
                 break;



                default:    
                 break;
             }

         }


        });
    }

    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) {
            View grid;

            if (convertView == null) { // if it's not recycled, initialize some
                // attributes
                grid = new View(mContext);
                LayoutInflater inflater = getLayoutInflater();
                grid = inflater.inflate(R.layout.moodcus, parent, false);

            } else {
                grid = (View) convertView;

            }
            ImageView imageView = (ImageView) grid.findViewById(R.id.imgview);
            TextView textView = (TextView) grid.findViewById(R.id.txtview);
            imageView.setImageResource(mThumbIds[position]);
            textView.setText(mMoodnames[position]);
            return grid;
        }

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

        private String[] mMoodnames = { "Angry", "Bored"};
    }


}

xml are

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <ImageView android:id="@+id/imgview" android:layout_width="60dip"
        android:layout_height="60dip" android:layout_gravity="center" />


    <TextView android:id="@+id/txtview" android:layout_width="wrap_content"
        android:textColor="#ffffff" android:layout_height="wrap_content"
        android:layout_gravity="center" />

</LinearLayout>

and

<?xml version="1.0" encoding="utf-8"?>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:verticalSpacing="5dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="80dp"
android:stretchMode="columnWidth"
android:gravity="center_horizontal"
    android:scaleType="fitXY"
 android:background="@drawable/ac"
/>

logcat

07-13 05:16:17.642: ERROR/AndroidRuntime(28966): Uncaught handler: thread main exiting due to uncaught exception
07-13 05:16:17.782: ERROR/AndroidRuntime(28966): android.content.ActivityNotFoundException: Unable to find explicit activity class {Dynamicgrid.test/Dynamicgrid.test.a}; have you declared this activity in your AndroidManifest.xml?
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.app.Activity.startActivityForResult(Activity.java:2789)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.app.Activity.startActivity(Activity.java:2895)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at Dynamicgrid.test.Mood$1.onItemClick(Mood.java:39)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.widget.AbsListView.onKeyUp(AbsListView.java:1757)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.widget.GridView.commonKey(GridView.java:1470)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.widget.GridView.onKeyUp(GridView.java:1382)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.view.KeyEvent.dispatch(KeyEvent.java:1249)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.view.View.dispatchKeyEvent(View.java:3683)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:758)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:760)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:760)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:760)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1691)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1111)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.app.Activity.dispatchKeyEvent(Activity.java:2045)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1667)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2390)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2360)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.os.Looper.loop(Looper.java:123)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at android.app.ActivityThread.main(ActivityThread.java:4595)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at java.lang.reflect.Method.invokeNative(Native Method)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at java.lang.reflect.Method.invoke(Method.java:521)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-13 05:16:17.782: ERROR/AndroidRuntime(28966):     at dalvik.system.NativeStart.main(Native Method)
  • 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-23T17:42:37+00:00Added an answer on May 23, 2026 at 5:42 pm

    Declare activity a also b if not in AndroidManifest.xml thats it

    In res/menu folder put this file yourmenu.xml

    <menu xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:id="@+id/menuitem1"
            android:title="Option1"
            android:orderInCategory="1"
            android:icon="@drawable/_icon1">
        </item>
        <item
            android:id="@+id/menuitem2"
            android:title="Option2"
            android:orderInCategory="2"
            android:icon="@drawable/_icon2">
        </item>
        <item
            android:id="@+id/menuitem3"
            android:title="Option3"
            android:orderInCategory="3"
            android:icon="@drawable/_icon3">
        </item>
    </menu>
    

    For opening onother Activity from menu …

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    
        // SELECTING MENU FROM RESOURCE 
        getMenuInflater().inflate(R.menu.ypurmenu, menu);
    
        // RETURN TRUE TO DISPLAY MENU
        return true;
    
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {  
    
        if(item.getTitle().equals("Option1") ){
    
            startActivity(new Intent(getApplicationContext(), AnotherActivityX.class)); // It Can be your GridViewActivity
            finish();
    
        }
        else if(item.getTitle().equals("Option2") ){
    
            startActivity(new Intent(getApplicationContext(), AnotherActivityY.class));
            finish();
    
        }
        else if(item.getTitle().equals("Option3") ){
    
            startActivity(new Intent(getApplicationContext(), AnotherActivityZ.class));
            finish();
    
        }
    
        return super.onOptionsItemSelected(item);
    
    }
    

    Or if you want to open any activity directly when user press menu button than there is simple solution …

     @Override
        public boolean onCreateOptionsMenu(Menu menu) {
             startActivity(new Intent(this, AnyActivity.class));//Also you can write finish() here if if you want to back at previous activity
            return super.onCreateOptionsMenu(menu);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i'm working on an app where i'm basically just making a custom multi
First of all, Hello everyone(/world) ! I am making an Eclipse RCP app' who
Hello guys i'm making a little app in which i need to enumerate all
Hello I'm making a mailbox for my website and I want it to show/hide
Hello everyone first of all. I am making an application for android, which I
Hello i am making an static library for distribution. I am distributing the .h
I'm experimenting with internationalization by making a Hello World program that uses properties files
Hello I am having a hard time making this UI element look the way
Hello , I am currently working on the student association's website. The student's association
Hello all you helpful folks @ stackoverflow! Best resources for Java GUI's? Looking at

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.