0

I am trying to update the ListView data on button click in the ListView But I am getting the following error:

4193-4193/kanix.highrise.com.highrise W/View﹕ requestLayout() improperly called by android.widget.TextView{69deba1 V.ED.... ......ID 381,134-423,163 #7f0a00e0 app:id/tvCQty} during layout: running second layout pass
07-10 13:06:34.099    4193-4193/kanix.highrise.com.highrise W/View﹕ requestLayout() improperly called by android.widget.TextView{e8e91c6 V.ED.... ......ID 223,198-235,227 #7f0a00df app:id/tvCompQty} during layout: running second layout pass
07-10 13:06:34.099    4193-4193/kanix.highrise.com.highrise W/View﹕ requestLayout() improperly called by android.widget.TextView{28429587 V.ED.... ......ID 107,134-185,163 #7f0a00de app:id/tvTQty} during layout: running second layout pass
07-10 13:10:24.337

I am trying to update the TextView value on button click in the ListView but problem is sometimes it updates the correct TextView and sometimes it updates wrong TextView in the same ListView.Any help regarding this issue will be appreciated.Thanks in advance.

My GetView Method is like this:

  @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            View view = convertView;

            if (view == null) {
                lInflater = (LayoutInflater) ctx .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = lInflater.inflate(R.layout.style_workcompletion
                        , parent, false);



                holder = new ViewHolder();

                holder.tvTask = (TextView) view.findViewById(R.id.tvTask);
                holder.tvPS=(TextView)view.findViewById(R.id.tvPS);
                holder.tvCQty=(TextView)view.findViewById(R.id.tvCQty);


                holder.tvCompQty= (TextView) view.findViewById(R.id.tvCompQty )   ;
                holder.tvTQty=(TextView)view.findViewById(R.id.tvTQty);
                holder.etCompQty  = (EditText) view.findViewById(R.id.etCompQty );
                holder.btnRefreshWoQty =(Button)view.findViewById(R.id.btnRefreshWOQty);
                //SelectQuantity=(EditText)findViewById(R.id.etSQuantity);
                view.setTag(holder);

                //  tvAQuantity.setText(p.getAQ());
                //   etQuantity.setTag(position);

            }
            else {

                holder=(ViewHolder)view.getTag();
            }
            holder.btnRefreshWoQty.setOnClickListener(null) ;// you need to set listener to null.

            p = getProduct(position);
            if(p!=null) {
                if (holder.tvCompQty != null) {

               Log.d("all details",p.getTotalQty()+"-"+p.getCumulative_Qty()+"-"+p.getCompQty());

                    holder.tvTask.setText(p.getTASKNM() );
                    holder.tvPS.setText(p.getPS());
                    holder.tvCQty.setText(p.getCumulative_Qty());
                    holder.tvCompQty.setText(p.getCompQty());
                    holder.tvTQty.setText(p.getTotalQty());
                    holder.etCompQty.setText("0.0");



                }
            }

            final int     posi=position;

            holder.btnRefreshWoQty.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    RelativeLayout  rl = (RelativeLayout)v.getParent();

                    holder.tvCompQty = (TextView) rl .findViewById(R.id.tvCompQty );
                    holder.tvCQty = (TextView) rl .findViewById(R.id.tvCQty);
                    holder.tvTQty = (TextView) rl .findViewById(R.id.tvTQty);
                    holder.etCompQty=(EditText)rl.findViewById(R.id.etCompQty );

                    if((Float.parseFloat (holder.tvTQty.getText().toString())-Float.parseFloat (holder.tvCQty.getText().toString()))>=Float.parseFloat (holder.etCompQty.getText().toString()))
                    {
                        p = getProduct(posi);
                        p.setCompQty(holder.etCompQty.getText().toString());

                        lstItems .get(position).setCompQty(holder.etCompQty.getText().toString());
                        Log.d("compQty",p.getCompQty());
                        Log.d("cumQty",p.getCumulative_Qty( ));
                        Log.d("tQty",p.getTotalQty());
                        notifyDataSetChanged();
                    }
                    else
                    {
                        Toast.makeText(myactivity,"Quantity should be less than pending quantity!",Toast.LENGTH_SHORT).show();

                    }
                }
            });






            //  CheckBox cbBuy = (CheckBox) view.findViewById(R.id.checkbox);
            //cbBuy.setOnCheckedChangeListener(myCheckChangList);
            //  cbBuy.setTag(position);
            //  cbBuy.setChecked(p.selected);
            return view;
        }

Here is the layout file for my xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:background="#2658A7"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Task:"
        android:textColor="#FFF"
        android:id="@+id/textView3" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="task"
        android:textColor="#FFF"
        android:id="@+id/tvTask"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/textView3"
        android:layout_toEndOf="@+id/textView3"
        android:layout_marginLeft="25dp"
        android:layout_marginStart="25dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="P.Schedule:"
        android:textColor="#FFF"
        android:id="@+id/textVdiew3"

        android:layout_below="@+id/textView3"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="25dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ps"
        android:textColor="#FFF"
        android:id="@+id/tvPS"
        android:layout_alignTop="@+id/textVdiew3"
        android:layout_toRightOf="@+id/textVdiew3"
        android:layout_toEndOf="@+id/textVdiew3" />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Total Qty:"
        android:textColor="#FFF"
        android:id="@+id/tedxtVdiew3"

        android:layout_below="@+id/textVdiew3"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="25dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TQty"
        android:textColor="#FFF"
        android:id="@+id/tvTQty"


        android:layout_alignTop="@+id/tedxtVdiew3"
        android:layout_toRightOf="@+id/textVdiew3"
        android:layout_toEndOf="@+id/textVdiew3" />




    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cumulative Qty:"
        android:id="@+id/tedsdf3"
        android:textColor="#FFF"
        android:layout_above="@+id/textView625"
        android:layout_toRightOf="@+id/tvCompQty"
        android:layout_toEndOf="@+id/tvCompQty" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CQty"
        android:id="@+id/tvCQty"
        android:textColor="#FFF"

        android:layout_above="@+id/textView625"
        android:layout_toRightOf="@+id/tedsdf3"
        android:layout_toEndOf="@+id/tedsdf3" />







    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Completed Qty:"
        android:id="@+id/textView625"
        android:layout_weight="1"
        android:textColor="#FFF"
        android:layout_below="@+id/tedxtVdiew3"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="23dp" />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="com Qty"
        android:id="@+id/tvCompQty"
        android:layout_weight="1"
        android:textColor="#FFF"
        android:layout_alignTop="@+id/textView625"
        android:layout_toRightOf="@+id/tvTQty"
        android:layout_toEndOf="@+id/tvTQty"
        android:layout_marginLeft="25dp"
        android:layout_marginStart="25dp" />
    <EditText
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:text=""
        android:id="@+id/etCompQty"
        android:layout_weight="1"
        android:textColor="#FFF"
        android:singleLine="true"
        android:width="120dp"
        android:background="@drawable/edittext_bg"
        android:textColorLink="#000"
        android:inputType="numberDecimal"
        android:layout_alignTop="@+id/tvCompQty"
        android:layout_toLeftOf="@+id/btnRefreshWOQty"
        android:layout_toStartOf="@+id/btnRefreshWOQty" />
    <Button
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/refresh1"
        android:id="@+id/btnRefreshWOQty"
        android:layout_alignBottom="@+id/etCompQty"
        android:layout_alignRight="@+id/tvCQty"
        android:layout_alignEnd="@+id/tvCQty" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray"
        android:layout_marginTop="102dp"
        android:id="@+id/view"
        android:textColor="#FFF"

        android:layout_below="@+id/tvPS"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>
Xgamer
  • 33
  • 1
  • 8

3 Answers3

0

Use OnItemClickListener of ListView Then you'll get the item and position to perform your task.

user3290180
  • 4,260
  • 9
  • 42
  • 77
0

@Xgamer : Your textView might not be properly placed in the XML file. Please check it out.

Surya
  • 628
  • 3
  • 9
  • 26
  • Sometimes, the elemets in the xml file overlaps other elements, or the specific space allocated for a particular element will be touched by some other element. In such cases, these kinda errors might rise. Try this also http://stackoverflow.com/questions/24598977/android-requestlayout-improperly-called – Surya Jul 10 '15 at 09:13
  • every thing in xml is ok. – Xgamer Jul 10 '15 at 09:25
  • android:fastScrollEnabled="true" android:fastScrollAlwaysVisible="true"............... You have something like this, then you can remove it. See if it works. – Surya Jul 10 '15 at 09:44
  • Else, can you please post your xml file? Because I am sure the code is right. – Surya Jul 10 '15 at 09:45
  • view = vi.inflate(R.layout.listitemrow, parent, false); try this if you are inflating your relative layout. – Surya Jul 10 '15 at 11:11
  • where to use it can you please show me.I am confused – Xgamer Jul 10 '15 at 11:14
  • If you are using View anywhere in your code to call the listItem, then you can inflate that view by using the above code. It might be in onClick. I am not able to be more precise about it. Either it might be a problem with xml file or it is the above error. Other than that i find the code perfectly normal. – Surya Jul 10 '15 at 11:29
  • I am using view = lInflater.inflate(R.layout.style_workcompletion , parent, false); in the getview do I need to modify this line – Xgamer Jul 10 '15 at 11:44
0

If you want to refresh lisview from adapter then Instead of notifyDataSetChanged();

call AdapterClassName.this.notifyDataSetChanged();

Arth Tilva
  • 2,496
  • 22
  • 40