2015-07-10 33 views
0

我試圖更新ListView控件按鈕點擊ListView的數據,但我收到以下錯誤:試圖更新按鈕ListView的數據然後在Android

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 

我試圖更新TextView的價值在按鈕上點擊ListView,但問題有時它會更新正確的TextView,有時它會在同一個ListView中更新錯誤的TextView.Any有關此問題的幫助將不勝感激。提前感謝。

我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> 

回答

0

使用OnItemClickListenerListView 那麼你會得到項目和位置進行你的任務。

+0

但我想這個邏輯被執行在一個特定的按鈕點擊 – Xgamer

0

@Xgamer:您的textView可能沒有正確放置在XML文件中。請檢查一下。

+0

正確放置的手段?錯誤的ID或其他東西 – Xgamer

+0

有時,xml文件中的元素與其他元素重疊,或者爲特定元素分配的特定空間將被其他元素觸及。在這種情況下,這些有點錯誤可能會增加。試試這也http://stackoverflow.com/questions/24598977/android-requestlayout-improperly-called – Owner

+0

在xml中的每件事情都可以。 – Xgamer

0

如果要刷新適配器的lisview,然後 而不是notifyDataSetChanged();

call AdapterClassName.this.notifyDataSetChanged();

相關問題