0

我有一个名为 AdapterFilaProducto.java 的类,该类在列表中显示某些信息。

这是我的课

public class AdapterFilaProducto extends BaseAdapter {
  protected Activity activity;
  protected ArrayList<ItemFilaProducto> items;
  protected ItemFilaProducto item;
  protected String tipo;
  protected Mascaras msk = new Mascaras();
  public ImageButton btnImDerecha ;
  public ImageButton btnImIzquierda;
  public TextView producto;
  private Venta contex;
   TextView precio;
private BaseDataAdapter db;
private TextView precioCantidad;

  public AdapterFilaProducto(Activity activity, ArrayList<ItemFilaProducto> items,String tipo) {
    this.activity = activity;
    this.items = items;
    this.tipo = tipo;
  }
  public AdapterFilaProducto(Activity activity,Venta contex, ArrayList<ItemFilaProducto> items,String tipo) {
        this.activity = activity;
        this.items = items;
        this.tipo = tipo;
        this.contex=contex;
      }

  public int getCount() {
    return items.size();
  }


  public Object getItem(int position) {
    return items.get(position);
  }


  public long getItemId(int position) {
    return items.get(position).getId();
  }
  public String getItemProducto(int position) {
        return items.get(position).getProducto();
      }
  public String getItemCantidad(int position) {
        return items.get(position).getCantidad();
      }
  public String getItemPercio(int position) {
        return items.get(position).getPrecio();
      }
  public EditText getItemEdit(int position) {
        return items.get(position).getEditTxt();
      }

  public View getView(int position, View convertView, ViewGroup parent) 
  {

    db = new BaseDataAdapter(activity);

    View vi=convertView;
    final ItemFilaProducto item = items.get(position);

    if(convertView == null) 
    {
              LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              vi = inflater.inflate(R.layout.list_producto, null);
    }  


       btnImDerecha = (ImageButton) vi.findViewById(R.id.BtnDerechaVenta);
       btnImIzquierda = (ImageButton) vi.findViewById(R.id.BtnIzquierdaVenta);
       TextView producto = (TextView) vi.findViewById(R.id.txtProductoVenta);
       item.precio = (TextView) vi.findViewById(R.id.txtCantidadVenta);
       item.edtxt = (EditText) vi.findViewById(R.id.editTxtListVenta);
       producto.setText(item.getProducto());
       Log.i("Precio",item.montoPrecio);
       if(item.cantidad.equalsIgnoreCase("0")){
           item.precio .setText(item.Precio);
       }else 
           item.precio .setText(item.montoPrecio);

       item.edtxt.setText(""+item.cantidad);

       btnImDerecha.setOnClickListener(new OnClickListener() {

             @Override
                public void onClick(View v) {
                    int i = Integer.parseInt(item.edtxt.getText().toString());
                    i=i+1;
                    item.edtxt.setText(""+i);

             }
            });
       btnImIzquierda.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    int i = Integer.parseInt(item.edtxt.getText().toString());
                      if(0<i){
                        i=i-1;
                        item.edtxt.setText(""+i);



                        }
             }
            });
               item.edtxt.addTextChangedListener(new TextWatcher() {
               public void afterTextChanged(Editable s)
               { 

               }
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {


            }
            public void onTextChanged(CharSequence s, int start, int before, int count) { 
                db.open();
                Cursor cur = db.obtenerProductosTipo(tipo,item.getIdPro());
                if(cur.moveToFirst()){
                    int precio = cur.getInt(3);
                    int cantidad = Integer.parseInt(item.edtxt.getText().toString());
                    int monto = precio*cantidad;
                    if(0 < monto){
                        item.setPrecio(msk.mascaraMontoTxt(String.valueOf(monto)));
                        item.precio .setText(item.getPrecio());
                    }
                    db.actualizarProductoMonto(item.getIdPro(),monto);
                    db.actualizarProductoCantidad(item.getIdPro(),cantidad);
                }
                cur.close();
                int montoTotal = 0;
                Cursor curAll = db.obtenerProductosTipo(tipo);
                if(curAll.moveToFirst()){

                    do{
                        montoTotal = montoTotal + curAll.getInt(5);
                        Log.e("CANTIDAD", ""+curAll.getInt(5));
                    }while(curAll.moveToNext());
                    }

                curAll.close();
                try{
                    db.borrarTablaPar("MONTO");
                }catch(Exception e){

                }
                Log.e("MONTO", ""+montoTotal);
                DtoParametro dtoParametro = new DtoParametro();
                dtoParametro.ID_PAR = "MONTO";
                dtoParametro.VALOR = String.valueOf(montoTotal);
                Log.i("MONTO",""+String.valueOf(montoTotal));
                db.insertarParametro(dtoParametro);
                db.close();
                contex.mostrarMonto();

            }
            });
    return vi;
  }     
}

而我需要做的是在我的主要 Activity 中显示montoTotal。并在我的 Principal Activity 的 Textview 中显示它的总量。我们尝试了几种方法,但都没有成功。我会很感激你的帮助,谢谢。

4

1 回答 1

0

Its really hard to follow your code but you should either be able to make this an inner class of your PrincipalActivity and make montoTotal a member variable so that you can access it from where you need or create an instance of this class that retrieves the variable from a function

于 2013-02-19T19:15:36.143 回答