2011-11-13 7 views
0

を更新し、ビューは、ユーザーが今問題があることである私がAndroidのリストビュー、ビューのセルだけ私はカスタムアレイアダプタとリストビューを持って一度

を実装し、いくつかのプラスとマイナスボタンで上下変数を変更することができますプラス/マイナスボタンはビューを一度変更しますが、その時間が経過すると、ビューが別の方法でリフレッシュされるまで更新されません。外部操作でlistview.notifydatasetchanged()を使用するようなものです。

それが更新するとき、それはデータの更新時に個々のではない理由、それはすぐにビュー

に正しい変数を置く設定しているため、プラス/マイナスボタンは、クリックを登録すると、変数を更新したことを示していますそれ自身で更新を表示しますか?

private class MyListAdapter extends ArrayAdapter<Item> { 

    private ArrayList<Item> items; 
    TextView quantity; 
    int i; 

    public MyListAdapter(Context context, int textViewResourceId, ArrayList<Item> items) { 
     super(context, textViewResourceId, items); 
     this.items=items; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     View v = convertView; 
     if (v == null) { 
      LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      v = vi.inflate(R.layout.list_scanneditems, null); 
     } 

      final Item allItems = items.get(position); 




     //declare all parts of the cell 
     TextView product = (TextView)v.findViewById(R.id.productName); 
     quantity = (TextView)v.findViewById(R.id.listNum); 
     TextView category = (TextView)v.findViewById(R.id.categoryName); 
     TextView price = (TextView)v.findViewById(R.id.productCost); 

     product.setText(allItems.product); 
     category.setText(allItems.category); 
     price.setText("$" + allItems.price); 
     quantity.setText(String.valueOf(allItems.quantity)); //might want to do ceiling and floor functions here, IF weight not present 

     //set properties within on click listeners 
     //items.set(position, allItems.quantity); 

     ImageView selectLeft = (ImageView)v.findViewById(R.id.selectleft_list); 
     ImageView selectRight = (ImageView)v.findViewById(R.id.selectright_list); 

     CheckBox itemCheckBox = (CheckBox)v.findViewById(R.id.itemCheckBox);   

     itemCheckBox.setChecked(selectallListener); 

     itemCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){ 

      @Override 
      public void onCheckedChanged(CompoundButton buttonView, 
        boolean isChecked) { 
       // TODO Auto-generated method stub 
       if(isChecked==false && selectallListener==true) 
       { 
        selectallListener=false; 

        CheckBox selectAll = (CheckBox)findViewById(R.id.selectAll); 
        selectAll.setChecked(false); 
       } 
      } 

     }); 


     selectLeft.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       if(allItems.quantity > 0) //i greater than 0, decrement -1 
       { 
        allItems.setQuantity(allItems.quantity-1); 
        quantity.setText(String.valueOf(allItems.quantity)); 
       } 
       else //i less or equal to 0 
       { 

        allItems.setQuantity(0); 
        quantity.setText(String.valueOf(allItems.quantity)); 

        //turn icon into an X here an if it is X delete the item 

       } 

      }//onclick 

     });//selectleft listener 

     selectRight.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       allItems.setQuantity(allItems.quantity+1); 
       quantity.setText(String.valueOf(allItems.quantity)); 

      }//onclick 

     });//selectRight listener 

     //do I need viewholder here? 

     //set listeners 


     return v; 
    } 

答えて

1

数量変数は、クリックが発生した現在のビューとは無関係である可能性があります。今度は、常に最後のgetView呼び出しでTextViewが作成/処理されます。

私はallItems変数のようにする必要がありますと思う。 getViewメソッド関数の

最終のTextView量= ...

+0

あなたは私が何をすべきかを示唆していますか? – CQM

+0

クラス変数の代わりに、ローカル/関数変数を使用します。ちょうどallItems(どのような誤解を招く名前)変数のように。 ... //セルのすべての部分を宣言します。 TextView product =(TextView)v.findViewById(R.id.productName); 最終TextView数=(TextView)v.findViewById(R.id.listNum); ... – Deucalion

+0

これはうまくいきました、ありがとうございます – CQM

関連する問題