ViewFlipper ListView中排 [英] ViewFlipper in ListView row

查看:160
本文介绍了ViewFlipper ListView中排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有对每一行的XML视图一个ListView。

I have a ListView with an XML view for each of the rows.

在每一行有一个ViewFlipper和一个Button,其意图是preSS按钮,并通过对ViewFlipper的意见翻转。

On each row there is a ViewFlipper and a Button, the intention being to press the button and flip through the views on the ViewFlipper.

问题是我不能让按钮翻转正确ViewFlipper。我设置的行了在ListView适配器所以我想这是我应该处理按钮的点击。

The problem is I can not get the Button to flip the correct ViewFlipper. I am setting the row up in the ListView adapter so I assume this is where I should handle the button click.

虽然点击被处理时,被ViewFlipper翻转是在不同的行。我想这是因为适配器是回收的意见 - 我只是不知道如何解决这个

Although the click is being handled, the ViewFlipper being 'flipped' is on a different row. I assume this is because the adapter is recycling the views - I just can not work out how to resolve this.

我的code是

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

    if (convertView == null) {
        convertView = mLayoutInflater.inflate(mLayout, null);

        viewHolder = new ViewHolder();
        viewHolder.flipper = (ViewFlipper) convertView.findViewById(R.id.viewConfFlipper1);
        viewHolder.v2FieldName = (TextView) convertView.findViewById(R.id.tvLongName);
        viewHolder.button01 = (ImageButton) convertView.findViewById(R.id.imageButton1);

        viewHolder.button01.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                viewHolder.flipper.showNext();
            }
        });

        convertView.setTag(viewHolder);

    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

    viewHolder.v2FieldName.setText(items.get(position).get("name"));

    return convertView;
}

任何帮助AP preciated

Any help appreciated

推荐答案

设法得到它现在的工作中,code是

Managed to get it working now, the code is

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

    final ViewFlipper flipperTemp;

    if (convertView == null) {
        convertView = mLayoutInflater.inflate(mLayout, null);

        viewHolder = new ViewHolder();
        viewHolder.flipper = (ViewFlipper) convertView.findViewById(R.id.viewConfFlipper1);
        viewHolder.flipper.setDisplayedChild(0);
        viewHolder.v2FieldName = (TextView) convertView.findViewById(R.id.tvLongName);
        viewHolder.button01 = (ImageButton) convertView.findViewById(R.id.imageButton1);    
        convertView.setTag(viewHolder);

    } else {
        viewHolder = (ViewHolder) convertView.getTag();
        viewHolder.flipper.setDisplayedChild(0);
    }


    flipperTemp = (ViewFlipper) convertView.findViewById(R.id.viewConfFlipper1);

    viewHolder.v2FieldName.setText(items.get(position).get("name"));        
    viewHolder.button01.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            flipperTemp.showNext();
        }
    });

    return convertView;
}

这篇关于ViewFlipper ListView中排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆