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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:56:08+00:00 2026-05-26T04:56:08+00:00

There is an really weird thing happening with my listview. I am creating an

  • 0

There is an really weird thing happening with my listview. I am creating an ListView with buttons and an editText.

It’s disposed like this: [Button] [EditText] [Button], The buttons works like an “incrementer” and “decrementer” updating the numerical value of EditText in 1 unit per click.
The problem is, when I click in an button, almost every time an editText of another list view element is changed (the editText of the clicked item is also changed). And if I click in a button of this erroneous changed item, it also changes the editText of the first one. They basically have the same reference of buttons and editText, although they have textViews with data, and this data is different between they.

To accomplish that I created and custom adapter:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView == null) {
            convertView = mInflater.inflate(R.layout.lastproduct_row, null);
            holder = new ViewHolder();
            holder.btnAddQtd = (Button) convertView.findViewById(R.lastproduct_row.btn_add_qtd);
            holder.btnSubQtd = (Button) convertView.findViewById(R.lastproduct_row.btn_sub_qtd);
            holder.etQuantidade = (EditText) convertView.findViewById(R.lastproduct_row.et_quantidade);                

            TextView tv;

            holder.tvList = new TextView[PRODUCTROW_INT_KEY.length];

            for(int i = 0; i < PRODUCTROW_INT_KEY.length; i++) {
                tv = (TextView) convertView.findViewById(PRODUCTROW_INT_KEY[i]);
                holder.tvList[i] = tv;                  
            }

            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }

        HashMap<String, String> hm = productsList.get(position);
        String key = hm.get(CODIGO_KEY);

        for(int i = 0; i < PRODUCTROW_INT_KEY.length; i++) {
            holder.tvList[i].setText(hm.get(PRODUCTROW_STR_KEY[i]));
        }

        holder.btnAddQtd.setTag(key+QTD_FLAG+ADD_ACTION);
        holder.btnSubQtd.setTag(key+QTD_FLAG+SUB_ACTION);
        holder.btnAddQtd.setOnClickListener(handle);
        holder.btnSubQtd.setOnClickListener(handle);

        if(novosEstoques.containsKey(key)) {
            holder.etQuantidade.setText(MyParseFunctions.parseCentesimal(novosEstoques.get(key).getQuantidade()));
        }

        return convertView;
    }

    class ViewHolder {
        private TextView []tvList;
        private Button btnAddQtd, btnSubQtd;
        private Button btnAddQtVol, btnSubQtVol;
        private EditText etQuantidade, etQtVolume;
    }

I added onClick listenners to the buttons, setting their tags with my listView element ID (concatenated with another informations). Then in my event listener I just get the button parent View (an LinearLayout) and get the EditText from that using getViewAt():

    @Override
    public void onClick(View v) {
        String tag = (String) v.getTag();

        if(tag.contains(QTD_FLAG)) {
            String []info = ((String) v.getTag()).split(QTD_FLAG);
            float qtd;
            LinearLayout ll = (LinearLayout) v.getParent();
            ll.setBackgroundColor(Color.rgb(0, 128, 30));
            EditText et = (EditText) ll.getChildAt(2);

            qtd = Float.parseFloat(et.getText().toString().replace(",", "."));

            if(info[1].equals(ADD_ACTION)) {
                qtd++;

            }
            else if(info[1].equals(SUB_ACTION)) {
                if(qtd > 0)
                    qtd--;
            }

            Log.d("TESTE", "MODIFICAR KEY = "+info[0]);
            et.setText(qtd+"");
        }           
    }

I’m using an setBackgroundColor in this example to confirm that the LinearLayout instance is duplicated in the lisView. When I click an Button, it’s painted in 2 different list view item.

Anyone can point me what could be doing this? I have found people with an duplicated ListView item, I don know if that is my case, cause I have TextView’s inside my ListView, and they are not equal, only the LinearLayout portion with buttons and editText is “shared”.


I make some changes in my getView method and it’s working now! It seems that every time the getView method is called i have not guarantee at all that my editTexts will be filled properly and I didn’t realize that. So every getView call I make I set the editText value, if the user edit an ET value, I store it in a HashMap to restore in getView, if there is no entry in HashMap for the given editText, then I set it to the default value (zero):

    ...
    if(convertView == null) {
            holder = new ViewHolder();
            holder.btnAddQtd = (Button) convertView.findViewById(R.lastproduct_row.btn_add_qtd);
            holder.btnSubQtd = (Button) convertView.findViewById(R.lastproduct_row.btn_sub_qtd);
            holder.etQuantidade = (EditText) convertView.findViewById(R.lastproduct_row.et_quantidade); 

            //Now it is easier to get etQuantidade reference in button
            //click handle, I just have to do:
            //    public onClick(View v) {
            //        EditText etButtonAssociated = (EditText) v.getTag();
            //        ...
            //    }
            holder.btnAddQtd.setTag(holder.etQuantidade);
            holder.btnSubQtd.setTag(holder.etQuantidade);

            holder.btnAddQtd.setOnClickListener(handle);
            holder.btnSubQtd.setOnClickListener(handle);
            ...
    }
    else {
        ...
    }
    holder.etQuantidade.setTag(key);

    if(novosEstoques.containsKey(key)) {
        holder.etQuantidade.setText(MyParseFunctions.parseCentesimal(novosEstoques.get(key).getQuantidade()));
    }
    else {
        holder.etQuantidade.setText("0");
    }

    return convertView;
  • 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-26T04:56:08+00:00Added an answer on May 26, 2026 at 4:56 am

    Israel,

    After looking over your code, I was wondering about an implementation decision you have made. Since each Button is “bound” to a particular EditText, have you considered setting the Tag of those Buttons to the EditText? The Tag may be any Object including a UI element. This is especially useful for dynamic UI elements, such as a runtime populated list.

    Since this is handled in your Adapter you wouldn’t have to worry about duplicate Parents and such. Additionally, you could avoid having to worry about “finding” the control in your onClick() because you would have it (It’s the tag). I’m not sure exactly what your project needs are, but this seems like a potentially viable solution, unless you need those Buttons to accomplish other tasks.

    Note of Caution
    Just make sure that you erase the Tags’ references to the EditText when you are done. Otherwise, you run the risk of leaking some memory.

    FuzzicalLogic

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

Sidebar

Related Questions

I have this really weird bug. When I scroll down my table view, down
im a newbie to flash,and i hav got this really weird problem.i have created
There is this weird bug in my program that I'm trying to fix, but
This is really weird - I've got a MVC app running, including a Login
Is there really a big difference between Eclipse 3.2 and 3.4? I am currently
Is there really a difference in these two calls? If you use getJSON, you
Is there really no way to print an ascii string in assembly to standard
Am I missing something or there really is no support for generic object type
I'm relatively new to Lisp, and I was wondering if there really is an
Is there a really good free tool for BugZilla reporting? I am finding the

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.