0

BaseAdapter を拡張するカスタム リストビューがあります。ボタンを押したときに textView/TextSwitcher の値を更新して表示しようとしています。

マイコード

private class myListAdapter extends BaseAdapter implements ViewFactory {
    Context mcontext;
    final int[] bgColors = new int[] { R.drawable.bg_even,
            R.drawable.bg_odd };
    private ArrayList<HashMap<String, Object>> Books;

    public myListAdapter(ArrayList<HashMap<String, Object>> arrayList,
            Context context) {
        Books = arrayList;
        mcontext=context;
        mInflater = LayoutInflater.from(context);
    }

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

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

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

    @SuppressWarnings("null")
    public View getView(final int position, View convertView,
            ViewGroup parent) {
        try {
            ViewHolder holder = null;

            if (convertView == null) {
                try {
                    convertView = mInflater.inflate(
                            R.layout.addtocart_inflate, null);
                    int colorPosition = position % bgColors.length;
                    convertView
                            .setBackgroundResource(bgColors[colorPosition]);

                    convertView.setClickable(true);
                    OnClickListener clickListener = null;
                    convertView.setOnClickListener(clickListener);
                    holder = new ViewHolder();
                    holder.tv1 = (TextView) convertView.findViewById(R.id.TextView03);
                    holder.decrease = (ImageView) convertView.findViewById(R.id.menu_decrease_order);
                    holder.increase = (ImageView) convertView.findViewById(R.id.menu_increase_order);


                    holder.mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
                    holder.mSwitcher.setFactory(this);
                    Animation in = AnimationUtils.loadAnimation(mcontext,
                            android.R.anim.fade_in);
                    Animation out = AnimationUtils.loadAnimation(mcontext,
                            android.R.anim.fade_out);
                    holder.mSwitcher.setInAnimation(in);
                    holder.mSwitcher.setOutAnimation(out);
                    convertView.setTag(holder);
                } catch (Exception ex) {
                }
            } else {
                holder = (ViewHolder) convertView.getTag();
                int colorPosition = position % bgColors.length;
                convertView.setBackgroundResource(bgColors[colorPosition]);
            }
            System.out.println("Name is " +Books.get(position).get("name"));
            holder.tv1.setText((String) Books.get(position).get("name"));

            holder.increase.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    mCounter++; 
                    System.out.println("value is " +mCounter);
                    String temp= Integer.toString(mCounter);
                    holder.mSwitcher.setText(temp); //Can't do this here as it says Change Holder to final 
                }
            });

        holder.decrease.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {

                    if(mCounter==0){

                    }else{
                        mCounter--;             
                        System.out.println("value is " +mCounter);

                    }
                }
            });


        } catch (Exception ex) {
            CommonUtils.postException(ex, ex.getMessage());
        }

        return convertView;
    }

    class ViewHolder {
        TextView tv1;
        ImageView increase,decrease;
        TextSwitcher mSwitcher;

    }

    public View makeView() {
        TextView t = new TextView(mcontext);
        t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
        t.setTextSize(36);
        return t;
    }
}

ボタンを押すと数量を増減して画面に表示したい。値が変更されるたびに listView 値をリロードすることで、問題を解決する 1 つの方法を知っています。

しかし、私が探しているのは

値をリロードせずに、実行時に textView に値を表示する必要があります。上記の私のコードでは、「修飾子ホルダーを最終的に変更すると書かれています」ListViewをリロードせずにこれを行うにはどうすればよいですか。

4

1 に答える 1