尝试更新按钮上的ListView数据单击android

时间:2015-07-10 07:53:04

标签: android listview

我试图在ListView中点击按钮更新ListView数据但是我收到以下错误:

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

我正在尝试更新ListView中按钮单击时的TextView值,但问题是有时它会更新正确的TextView,有时它会在同一个ListView中更新错误的TextView。有关此问题的任何帮助将不胜感激。谢谢提前。

我的GetView方法是这样的:

  @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;
        }

这是我的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>

3 个答案:

答案 0 :(得分:0)

使用OnItemClickListener的{​​{1}} 然后你将得到项目和位置来执行你的任务。

答案 1 :(得分:0)

@Xgamer:您的textView可能未正确放置在XML文件中。请检查一下。

答案 2 :(得分:0)

如果要从适配器刷新lisview,那么 而不是notifyDataSetChanged();

调用AdapterClassName.this.notifyDataSetChanged();