简体   繁体   中英

trying to update the ListView data on button click android

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>

使用ListView OnItemClickListener然后,您将获得执行任务的项目和位置。

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

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

call AdapterClassName.this.notifyDataSetChanged();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM