2012-05-01 11 views
-1

私はカスタムリストビューでitemimage、itemname、price、qtyを表示する配列を取得しています。今私は、価格と数量を掛け合わせて計算されたもう1つのフィールド、合計を配置しています。アンドロイドのカスタムリストビューで価格と数量を掛け合わせる

私はこのコードを使用しています:

public class CustomAdapter extends BaseAdapter 
    { 
    integer[] a; 
public static ArrayList<String> arr1=new ArrayList<String>(); 
public static ArrayList<String> itemprice=new ArrayList<String>(); 
public static ArrayList<Bitmap> itemimage=new ArrayList<Bitmap>(); 
public Context Context; 
private LayoutInflater inflater; 
String total; 
    HashMap<String, String> map = new HashMap<String, String>(); 
    public CustomAdapter(Context context, ArrayList<String> arr,ArrayList<String> price,ArrayList<Bitmap> image) 
    { 
     Context=context; 
     inflater=LayoutInflater.from(context); 
     arr1=arr; 
     itemprice=price; 
     itemimage=image; 
     System.out.println(itemprice); 
     System.out.println("arr: " + arr.size()); 

     for(int i=0;i<price.size();i++) 
     { 

      String amonut=price.get(i); 
      int x=Integer.parseInt(amonut); 

     } 

    } 
    public int getCount() 
    { 
     // TODO Auto-generated method stub 
     return arr1.size(); 

    } 

    public Object getItem(int position) 
    { 
     // TODO Auto-generated method stub 
     return arr1.get(position); 
    } 

    public long getItemId(int position) 
    { 
     // TODO Auto-generated method stub 
     return position; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) 
     { 
     System.out.println(arr1.get(position)); 

      final ViewHolder holder; 

      if (convertView == null) 
      { 
       convertView = inflater.inflate(R.layout.selecteditemlistview, null); 
       holder = new ViewHolder(); 

       holder.textViewSelectedText = (TextView)convertView.findViewById(R.id.selectedtext); 
       holder.price=(TextView)convertView.findViewById(R.id.selectitemprice); 
       holder.image=(ImageView)convertView.findViewById(R.id.selectitemimagge); 
       holder.qty=(EditText)convertView.findViewById(R.id.selectqty); 
       holder.total=(TextView)convertView.findViewById(R.id.totalamount); 
       convertView.setTag(holder); 
      } 
      else 
      { 
       holder = (ViewHolder) convertView.getTag(); 
      } 
      String amount=holder.qty.getText().toString(); 

      holder.textViewSelectedText.setText(arr1.get(position)); 
      holder.price.setText(itemprice.get(position)); 
      holder.image.setImageBitmap(itemimage.get(position)); 

      return convertView;  
     } 

     class ViewHolder 
     { 
      TextView textViewSelectedText = null; 
      TextView price=null; 
      ImageView image=null; 
      EditText qty=null; 
      TextView total=null; 
     }  
} 

私はint型のxと文字列の量を乗算し、合計のテキストとして結果を割り当てます。あなたの条件に応じて

+2

の計算のために '' Integer.parse(のstringValue)を使用してみてください。 p.s.私たちの全員があなたではありません、いくつかの欠場もあります – thepoosh

答えて

1
ans = x * Integer.parseInt(amount); or 

ans = x * Double.parseDouble(amount); 

total = String.valueOf(ans); 
+0

このholder.total.setText(total.toString())を試してみてください; – MAC

+0

私はすべての価格を倍増させたい*数量私はデフォルトとして1を設定します。 – prakash

0

変更変数の型: -

private float getTotal(String quantity, String price) 
    { 
    float total = 0f; 

    try{ 
    float quant = Float.parseFloat(quantity); 
    float unitCost= Float.parseFloat(price); 

    total = unitCost*quant; 


    }catch (Exception e) { 

    } 

    return total; 
    } 
関連する問題