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 6329239
In Process

The Archive Base Latest Questions

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

my program is based on Google’s Hello Gallery example: http://developer.android.com/guide/tutorials/views/hello-gallery.html Instead of using images,

  • 0

my program is based on Google’s Hello Gallery example:
http://developer.android.com/guide/tutorials/views/hello-gallery.html
Instead of using images, I create a bunch of EditTexts in the constructor.

My question is now: When I long click on an EditText, I want its Context Menu (with “select all”, “copy” and so on) to be shown. I’ve tried setting an OnItemLongClickListener which calls the selected view via myGallery.getAdapter().getView(position, ...).showContextMenu(), but that runs into a StackOverflowError (that’s btw the reason why I posted my question here – ok, that one was lame.):

08-13 16:02:36.062: ERROR/AndroidRuntime(3400): FATAL EXCEPTION: main
java.lang.StackOverflowError
 at android.widget.AdapterView.getPositionForView(AdapterView.java:581)
 at android.widget.Gallery.showContextMenuForChild(Gallery.java:1049)
 at android.view.View.showContextMenu(View.java:2520)
 at de.test.gallery2.Main$1.onItemLongClick(Main.java:51)
 at android.widget.Gallery.dispatchLongPress(Gallery.java:1074)
 at android.widget.Gallery.showContextMenuForChild(Gallery.java:1055)

I have also tried to registerForContextMenu() the Gallery, then the EditTexts and then both, but everything failed. Does anbody of you have a solution?

Btw, the Gallery shows some other strange behaviour: When the application starts, the first EditText is centered but can’t be edited when i tap on it. But when I tap on the second one (which is not centered), I can edit that one without it being centered. When I center the second EditText, I can only edit the third one and so on. When I center the last one, focus appears to vanish entirely and nothing can be edited anymore.

I will probably marry you if you can help me. Any help is appreciated. And believe me – I did a lot of research before asking this question. Really.
Thanks a lot

m1ntf4n

EDIT

Here is the code of my Activity. Sorry for the double post, didn’t take the possibility of editing into consideration.

public class Main extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Gallery gallery = (Gallery) findViewById(R.id.gallery);
        gallery.setAdapter(new LocalAdapter(this));
        gallery.setSpacing(50);

        registerForContextMenu(gallery);

        //Register the EditViews for ContextMenu.
        for(int i = 0; i < gallery.getAdapter().getCount(); ++i) {
            registerForContextMenu(gallery.getAdapter().getView(i, null, null));
        }

        //This listener will cause a StackOverflowError.
        /*gallery.setOnItemLongClickListener(new Gallery.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> a, View v, int i, long l) {
                return gallery.getAdapter().getView(i, null, null).showContextMenu();
            }
        });*/
    }

    public class LocalAdapter extends BaseAdapter {
        private Context mContext;
        private EditText[] editText;

        public LocalAdapter(Context c) {
            mContext = c;
            editText = new EditText[5];
            for(int i = 0; i != editText.length; ++i) {
                editText[i] = new EditText(mContext);
                editText[i].setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                editText[i].setText("TEXT " + i);
                editText[i].setTextSize(30);
            }
        }
        @Override
        public int getCount() {
            return editText.length;
        }
        @Override
        public Object getItem(int position) {
            return position;
        }
        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return editText[position];
        }
    }
}
  • 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-24T17:37:15+00:00Added an answer on May 24, 2026 at 5:37 pm

    From Google’s documentation:

    public void registerForContextMenu (View view)

    Registers a context menu to be shown for the given view (multiple
    views can show the context menu). This method will set the
    View.OnCreateContextMenuListener on the view to this activity, so
    onCreateContextMenu(ContextMenu, View, ContextMenuInfo) will be called
    when it is time to show the context menu.

    As you can see from the documentation, onCreateContextMenu() will be called in Main before the context menu is shown. You will need to override this method to create your custom context menu.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a very simple HTML/AJAX based GUI for a Python program.
I have a Python-based program that adds events to a Google Calendar. To add
i am creating a bluetooth based server program in Bluez which basically handles connections
I develop a Python-based drawing program, Whyteboard . I have tools that the user
Based on the following simple program the bitwise left shift operator works only for
I had a Java program that I run thousand times based on a loop
I have a program which places structures in a linked list based on the
I am working on a program that encodes a file based on a supplied
I'm working on a program that will sort files based on extension I currently
I'm currently trying to create a program that estimates location based on signal strength.

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.