在适配器类android中刷新视图

时间:2016-05-06 07:08:18

标签: android

我想在适配器类中选择微调器项目时更新textview,但它会以错误的项目价格显示更新。我已经失去了很多时间来解决这个问题,这是我的代码

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity, android.R.layout.simple_dropdown_item_1line, arraylist.get(position).getProductUnit1());

        // Setting the array adapter containing country list to the spinner widget
        holder.tvproductBrandName.setAdapter(adapter);

        OnItemSelectedListener countrySelectedListener = new OnItemSelectedListener() {

            @Override

            public void onItemSelected(AdapterView<?> spinner, View container,
                    int position2, long id) {

                 i =Float.parseFloat(arraylist.get(position).getProductMRP1()[position2]);



                 holder.tvProductMRP.setText((arraylist.get(position).getProductMRP1()[position2]));

                holder.tvProductOriginalPrice
                .setText("Rs: "
                        + ((i -  Float.valueOf(arraylist.get(position)
                                        .getOfferValue()))*(Float.valueOf(arraylist.get(position).getProductQTY()))) + "");


                 OriginaiPrice =String.valueOf (i -  Float.valueOf(arraylist.get(position)
                        .getOfferValue()));


                appSession.setProductOriginal(OriginaiPrice);


            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
            }
        };


        // Setting ItemClick Handler for Spinner Widget
        holder.tvproductBrandName.setOnItemSelectedListener(countrySelectedListener);

1 个答案:

答案 0 :(得分:0)

你可以使用哈希映射来检查微调器中选择的位置或值,然后使用第二个hashMap来检查textView值与spinner的对应关系。

    private final HashMap<Integer, Integer> selectedSpinnerItems;
    private final HashMap<Integer, String> textViewValue;