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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:14:34+00:00 2026-06-14T19:14:34+00:00

I have an application that has a layout with ~150 editText’s and a mainActivity

  • 0

I have an application that has a layout with ~150 editText’s and a mainActivity that has an onClickListener for each of these editTexts, and a button which loops through them all and clears them.

The application was running fine, and without making any significant changes I am now getting the following logCat error everytime i start up the application:

Out of memory on a 2903056-byte allocation.

Is there any obvious bad practices I am doing here that is causing the memory loss?

Some of my code below as illustration (this is repeated many times obviously)

box0101.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            txtHint.setText(hintPrefix + onOneClick);
            return false;
        }
    });
    box0301.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            txtHint.setText(hintPrefix + onOneClick);
            return false;
        }
    });
    box0401.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            txtHint.setText(hintPrefix + onOneClick);
            return false;
        }
    });
    box0501.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            txtHint.setText(hintPrefix + onOneClick);
            return false;
        }
    });
    box0601.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            txtHint.setText(hintPrefix + onOneClick);
            return false;
        }
    });

and also some buttonclick listeners that set off some loops

    btnClear.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            clearBoard();               
        }
    });
    public void clearBoard() {
    final int ROW_COUNT = 14;
    final int COL_COUNT = 9;
    final String ROWS[] = {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15"};
    final String COLS[] = {"01","02","03","04","05","06","07","08","09","10"};

    for(int i=0; i<ROW_COUNT; i++) {
        for(int j=0; j<COL_COUNT; j++) {
            String a = ROWS[i];
            String b = COLS[j];
            int editTextId = getResources().getIdentifier("box" + a + b , "id", getPackageName());
            EditText et=(EditText)findViewById(editTextId);    
            et.setText("");
        }
    }
    }
  • 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-06-14T19:14:35+00:00Added an answer on June 14, 2026 at 7:14 pm

    As @alex.veprik mentioned: try to use one OnClickListener, and assign it to all your EditText-objects. If you create a new OnClickListener for every EditText-object, although they all do the same, this will eat a lot of your memory.

    Example)

    View.OnTouchListener boxListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            txtHint.setText(hintPrefix + onOneClick);
            return false;
        }
    });
    
    //boxes is a list of all your boxes
    for(int i=0; i < boxes.size(); i++) {
        boxes.get(i).setOnTouchListener(boxListener);
    }
    

    It might also be wise to put the creation of your EditText-objects in a loop, and to store only the list of all boxes in a member variable. So instead of having 150 variables, you now only need one for the list, while at the same time keeping all the references. (this doesn’t affect your memory problem, but it’s good code style)

    List<EditText> boxes = new ArrayList<EditText>();
    for (int i = 0; i < NBR_OF_BOXES; i++) {
        boxes.add(new EditText());
    }
    

    As @zapl recommended, it might also be good to use a memory profiler.

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

Sidebar

Related Questions

I have a simple application that has one edittext field, and one button. The
I have an android application that has a button which I want to have
I have an application that has 2 beans with the same name, but which
I have an application that has a primary layout of portrait (it is fixed
I've an application that has a widget already and have a service which updates
In my application i have an activity which has the following layout <?xml version=1.0
We have an application that has a database full of polygons (currently stored as
I have a application that has an activity that shows message logs. The thing
I have an application that has two localization options at the moment through .resx
I have an application that has two threads. The first one (the main thread)

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.