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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:39:06+00:00 2026-05-26T22:39:06+00:00

Just a basic question: If I have several dozen EditText fields that are part

  • 0

Just a basic question: If I have several dozen EditText fields that are part of a ListAdapter, how can the individual EditText fields know to which row they belong?

Currently I am using TextWatcher to listen for text input. I have tried extending TextWatcher so that I can pass in the position of the EditText to TextWatcher’s constructor.

However, when the soft keyboard pops up, the positions that correspond to the various EditText fields shuffle.

How can I track the EditText fields to their proper position?

I am using a GridView to lay things out. The layout of each item is an ImageView with a TextView and EditText field below it.

The text for each EditText is held in a global String array called strings. It is initially empty, and is updated by my TextWatcher class.

public void initList()
    {
        ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, R.layout.shape, strings)
        {
            @Override
            public View getView(final int position, View convertView, ViewGroup parent)  {
                if (convertView == null)  {
                    convertView = LayoutInflater.from(getContext()).inflate(R.layout.shape, null);
                }
                final String theData = getItem(position);
                final EditText editText = (EditText) convertView.findViewById(R.id.shape_edittext);
                editText.setText(theData);
                editText.addTextChangedListener(
                        new MyTextWatcher(position, editText)
                );

                ImageView image = (ImageView) convertView.findViewById(R.id.shape_image);
                image.setBackgroundResource(images[position]);

                TextView text = (TextView) convertView.findViewById(R.id.shape_text);
                if (gameType == SHAPES_ABSTRACT)
                    text.setText("Seq:");
                else
                    text.setVisibility(View.GONE);  

                return convertView;
            }

            @Override
            public String getItem(int position) {        return strings[position];       }
        };

        grid.setAdapter(listAdapter);
    }


private class MyTextWatcher implements TextWatcher {
    private int index;
    private EditText edittext;
    public MyTextWatcher(int index, EditText edittext) { 
               this.index = index; 
               this.edittext = edittext;    
        }
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
    public void onTextChanged(CharSequence s, int start, int before, int count) {}
    public void afterTextChanged(Editable s) {  strings[index] = s.toString();      }
    public void setIndex(int newindex) {  index = newindex;    }
}

When I click into the first EditText (see picture), the EditText shifts to the one under the smiley face.

Shows how the EditText fields are layed out

  • 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-26T22:39:06+00:00Added an answer on May 26, 2026 at 10:39 pm

    Not taking into account if this is a good UI design, here’s how you’d do it:

    public class TestList
    {
        public void blah()
        {
            ArrayAdapter<DataBucket> listAdapter = new ArrayAdapter<DataBucket>()
            {
    
                @Override
                public View getView(int position, View convertView, ViewGroup parent)
                {
                    if (convertView == null)
                    {
                        convertView = LayoutInflater.from(getContext()).inflate(R.layout.testlayout, null);
                    }
    
                    final DataBucket dataBucket = getItem(position);
                    final EditText editText = (EditText) convertView.findViewById(R.id.theText);
                    editText.setText(dataBucket.getSomeData());
                    editText.addTextChangedListener(new TextWatcher()
                    {
                        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
                        {
    
                        }
    
                        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
                        {
    
                        }
    
                        public void afterTextChanged(Editable editable)
                        {
                            dataBucket.setSomeData(editable.toString());
                        }
                    });
    
                    return convertView;
                }
            };
        }
    
        public static class DataBucket
        {
            private String someData;
    
            public String getSomeData()
            {
                return someData;
            }
    
            public void setSomeData(String someData)
            {
                this.someData = someData;
            }
        }
    }
    

    ‘DataBucket’ is a placeholder. You need to use whatever class you created to store the data that gets put into and edited in the edit text. The TextWatcher will have a reference to the data object referenced. As you scroll, the edit text boxes should get updated with current data, and text changes should be saved. You may want to track which objects were changed by the user to make data/network updates more efficient.

    * Edit *

    To use an int position rather than directly referencing the object:

    ArrayAdapter<DataBucket> listAdapter = new ArrayAdapter<DataBucket>()
    {
    
        @Override
        public View getView(final int position, View convertView, ViewGroup parent)
        {
            if (convertView == null)
            {
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.testlayout, null);
            }
    
            final DataBucket dataBucket = getItem(position);
            final EditText editText = (EditText) convertView.findViewById(R.id.theText);
            editText.setText(dataBucket.getSomeData());
            editText.addTextChangedListener(new TextWatcher()
            {
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
                {
    
                }
    
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
                {
    
                }
    
                public void afterTextChanged(Editable editable)
                {
                    getItem(position).setSomeData(editable.toString());
                }
            });
    
            return convertView;
        }
    };
    

    * Edit Again *

    I feel compelled to say for posterity, I wouldn’t actually code it this way. I’d guess you want a little more structured data than a String array, and you’re maintaining the String array outside, as well as an ArrayAdapter, so its sort of a weird parallel situation. However, this will work fine.

    I have my data in a single String array rather than a multi-dimensional array. The reason is because the data model backing the GridView is just a simple list. That may be counterintuitive, but that’s the way it is. GridView should do the layout itself, and if left to its own devices, will populate the row with variable numbers of cells, depending on how much data you have and how wide your screen is (AFAIK).

    Enough chat. The code:

    public class TestList extends Activity
    {
        private String[] guess;
    
        //Other methods in here, onCreate, etc
    
        //Call me from somewhere else. Probably onCreate.
        public void initList()
        {
            ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, /*some resourse id*/, guess)
            {
    
                @Override
                public View getView(final int position, View convertView, ViewGroup parent)
                {
                    if (convertView == null)
                    {
                        convertView = LayoutInflater.from(getContext()).inflate(R.layout.testlayout, null);
                    }
    
                    final String theData = getItem(position);
                    final EditText editText = (EditText) convertView.findViewById(R.id.theText);
                    editText.setText(theData);
                    editText.addTextChangedListener(
                            new MyTextWatcher(position)
                    );
    
                    return convertView;
                }
            };
    
            gridView.setAdapter(listAdapter);
        }
    
        class MyTextWatcher extends TextWatcher {
             private int position;
    
             public MyTextWatcher(int position) {
                     this.position = position;
             }
    
             public void afterTextChanged(Editable s) {
                     guess[position] = s.toString();
             }
    
         // other methods are created, but empty
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this maybe a basic question but I just can't seem to find
Just a basic html link question. I have an intranet setup, and I need
Pretty basic question, I know... I just don't know how it's done. I want
This is probably a pretty basic question, but just something that I wanted to
Well i have a question that i feel i've been answered several times, from
I'm just getting started in F# and have a basic question. Here's the code:
this is a rather basic java question I have an array containing String that
I have a relatively basic question but more than anything just need some clarity
This is a pretty basic C++ design question: I have a class that contains
This is a very basic question. I'm just on my mission to learn ASP.NET

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.