2017-09-13 7 views
0

TextViewである商品カウンタを繰り返します。私は以下のシナリオを持っています:TextViewプロダクトカウンタはBaseAdapterを使用してグリッドビューで繰り返されるため、

  1. ユーザーは製品を選択してその数量を適用します。
  2. アクティビティから、アダプターからではなく、画像に表示されている選択された製品の数量が表示されます。
  3. すべてが画面下まで、完璧に動作し、カウンタが魔法のように、私が提案することで、これらのメソッドを実装している、他の製品に渡します

    @Override 
    public long getItemId(int position) 
    { 
        return position; 
    } 
    
    @Override 
    public int getItemViewType(int position) 
    { 
        return position; 
    } 
    

とまだ私はまだ、このエラーを取得します。私はまた、アダプタからカウンタを変更しようとしましたが、同じことが起こります。私はそのカウンターが固定され、画面の下に更新されないようにしたい。

アダプタ:

public class ProductoAdapter extends BaseAdapter 
    { 
    private Activity activity; 
    private LayoutInflater inflater; 
    private ArrayList<Producto> listadoProductos; 
    private ArrayList<Producto> productosPedidos; 

    Producto producto; 

    Empresas pedido; 

    public final int TYPE_NOTICIA=0; 
    public final int TYPE_LOAD=1; 
    private gestionSharedPreferences sharedPreferences; 
    private Context context; 
/* 
    OnLoadMoreListener loadMoreListener; 
*/ 
    boolean isLoading=false, isMoreDataAvailable=true; 
    vars vars; 
    public static int contador; 

    public static int i; 
    public static int contadorGeneral; 
    private NumberFormat numberFormat; 
    ImageLoader imageLoader = ControllerSingleton.getInstance().getImageLoader(); 

    public ProductoAdapter(Activity activity, ArrayList<Producto> listadoProductos) 
    { 
     this.activity=activity; 
     this.listadoProductos=listadoProductos; 
     productosPedidos=new ArrayList<Producto>(); 
     vars=new vars(); 
     sharedPreferences=new gestionSharedPreferences(this.activity); 
     contador=0; 
     contadorGeneral=0; 
     producto=new Producto(); 

     /* LocalBroadcastManager.getInstance(context).registerReceiver(mMessageReceiver, 
       new IntentFilter("custom-message"));*/ 
    } 

    /* public BroadcastReceiver mMessageReceiver = new BroadcastReceiver() 
    { 
     @Override 
     public void onReceive(Context context, Intent intent) 
     { 
      // Get extra data included in the Intent 
      producto = (Producto) intent.getSerializableExtra("producto"); 
      Toast.makeText(context, producto.getNombreProducto()+producto.getNumeroDeProducto() ,Toast.LENGTH_SHORT).show(); 
     } 
    };*/ 


    @Override 
    public int getCount() 
    { 
     return listadoProductos.size(); 
    } 

    @Override 
    public Producto getItem(int position) 
    { 
     return listadoProductos.get(position); 
    } 

    @Override 
    public long getItemId(int position) 
    { 
     return position; 
    } 

    @Override 
    public int getItemViewType(int position) 
    { 
     return position; 
    } 

    @Override 
    public View getView(int position, View view, ViewGroup viewGroup) 
    { 
     numberFormat = NumberFormat.getNumberInstance(Locale.GERMAN); 

     if (view == null) 
     { 
      LayoutInflater inflater = (LayoutInflater) activity 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      view = inflater.inflate(R.layout.producto_row_layout, viewGroup, false); 

      Log.i("martin","null"); 
     } 
     else 
     { 
      Log.i("martin","llenoooooooooo"); 
     } 
     final Producto producto = getItem(position); 

     ImageView imagenProducto = (ImageView) view.findViewById(R.id.imagenProducto); 

     TextView nombreProducto = (TextView) view.findViewById(R.id.nombreProducto); 
     TextView cantidadProducto = (TextView) view.findViewById(R.id.cantidadProducto); 
     TextView precioGeneralProducto = (TextView) view.findViewById(R.id.precioGeneralProducto); 
     TextView precioPideProducto = (TextView) view.findViewById(R.id.precioPideProducto); 
     TextView ahorroProducto = (TextView) view.findViewById(R.id.ahorroProducto); 



     if (producto.getImagenProducto().toString().equals("http://fasttrackcenter.com/pide/app/")) 
     { 
      imagenProducto.setImageResource(R.drawable.ic_not_image_found); 
     } 

     else 
     { 
      Glide.with(activity). 
        load(producto.getImagenProducto().toString()). 
        thumbnail(0.5f).into(imagenProducto); 
     } 

     nombreProducto.setText(producto.getNombreProducto()+" x "+producto.getCantidadProducto()+" "+producto.getUnidadProducto()); 

     //cantidadProducto.setText(producto.getCantidadProducto()); 
     precioGeneralProducto.setText("$"+numberFormat.format(Double.parseDouble(producto.getPrecioGeneralProducto()))); 
     precioGeneralProducto.setPaintFlags(precioGeneralProducto.getPaintFlags()| Paint.STRIKE_THRU_TEXT_FLAG); 
     precioPideProducto.setText("$"+numberFormat.format(Double.parseDouble(producto.getPrecioPideProducto()))); 
     int valorahorro=(Integer.parseInt(producto.getPrecioGeneralProducto()))-(Integer.parseInt(producto.getPrecioPideProducto())); 
     ahorroProducto.setText(""+"$"+numberFormat.format(Double.parseDouble(""+valorahorro))); 

     return view; 
    } 

} 

アクティビティー:

Iが最初に見えないカウンタとしてのTextViewを使用し、それが選択された場合、それが選択された製品の量に見えます。私はこの方法を使用するアクティビティから

@Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
    { 
     Producto producto = (Producto) parent.getItemAtPosition(position); 

     final View contadorImagenProductoBolsa = Pedidos.this.findViewById(R.id.contadorProductoImagenBolsa); 
     TextView test1TextView = (TextView) view.findViewById(R.id.contadorProductoImagenBolsa); 


     mostrarDialogoDetalle(test1TextView,position,producto.getIdProducto(),producto.getImagenProducto(), producto.getNombreProducto(), 
       producto.getCantidadProducto(),producto.getUnidadProducto(), producto.getPrecioGeneralProducto(),producto.getPrecioPideProducto(), 
       producto.getAhorroProducto()); 

    } 

は、誰もがこれが起こるがありましたか?彼らはどのようにそれを解決しましたか?

enter image description here

ここでは完璧ですが、私は、画面の下に行くと、私は背中と上がるとき、カウンタはどういうわけか他の製品に何が起こるかを観察:

enter image description here

私が欲しいです効果的なヘルプと、可能性のあるスニペットが表示されます。

ありがとうございます。

私はあなたがProductoAdapter等のViewHolderを追加する必要が考える
+0

役立つことを願いますその特定の位置をクリックすると、その位置をスクロールまたは移動している間にテキストのみが表示されます。これはあなたのリストビューが再使用セルであるために起こります。 –

答えて

0

:ViewHolder等の

class ViewHolder 
{ 
     TextView nombreProducto,cantidadProducto 
     ,precioGeneralProducto,precioPideProducto,ahorroProducto; 
     ImageView imagenProducto; 

public ViewHolder(View view){ 

    imagenProducto = (ImageView) view.findViewById(R.id.imagenProducto); 
    nombreProducto = (TextView) view.findViewById(R.id.nombreProducto); 
    cantidadProducto = (TextView) view.findViewById(R.id.cantidadProducto); 
    precioGeneralProducto = (TextView) view.findViewById(R.id.precioGeneralProducto); 
    precioPideProducto = (TextView) view.findViewById(R.id.precioPideProducto); 
    ahorroProducto = (TextView) view.findViewById(R.id.ahorroProducto); 


} 
} 

使用setTagとのgetTag:

ViewHolder holder; 
    if (view == null) 
    { 
     LayoutInflater inflater = (LayoutInflater) activity 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     view = inflater.inflate(R.layout.producto_row_layout, viewGroup, false); 
     holder = new ViewHolder(); 
     Log.i("martin","null"); 
    } 
    else 
    { holder = (ViewHolder) view.getTag(); 
     Log.i("martin","llenoooooooooo"); 
    } 

    final Producto producto = getItem(position); 
    if (producto.getImagenProducto().toString().equals("http://fasttrackcenter.com/pide/app/")) 
    { 
     holder.imagenProducto.setImageResource(R.drawable.ic_not_image_found); 
    } 

    else 
    { 
     Glide.with(activity). 
       load(producto.getImagenProducto().toString()). 
       thumbnail(0.5f).into(holder.imagenProducto); 
    } 

    holder.nombreProducto.setText(producto.getNombreProducto()+" x "+producto.getCantidadProducto()+" "+producto.getUnidadProducto()); 
    . 
    . 
    . 
view.setTag(holder); 
    return view; 

私は、これはあなたが保存する必要があります

+0

うまくいかない、それは繰り返す。 – FABiO

関連する問題