滚动图库可启用按下状态并从子项中删除单击侦听器

Leo*_*Leo 9 android listview scrollview android-gallery

我有一个相当复杂的项目库.每个项目由图像和2个按钮组成.当画廊加载一切正常时,按钮按照预期进行操作,按钮的按下状态仅在实际按下按钮时发生.

但是,只要我滚动图库,按钮就会停止工作,单击任意位置会启用按钮的按下状态.

我已经尝试将所有内容嵌入到LinearLayout中,但是根据这个答案没有传递OnDown事件,但这只会阻止点击事件.

我知道Gallery不是这种复杂布局的理想小部件,但我想知道是否有更好的解决方法来解决这个问题.

更新:

我会尝试解释一下这个架构.我有一个FragmentActivity,它包含一个ListFragment,它只由一个ListView组成.

ListView由较小元素组(Bettable)和一些元信息组成.这些组实现为Gallerys.具体来说,我有扩展的Gallery(称为OneGallery),它做了几件事,它确保一次只滚动一个项目,并在滚动发生时转换图库项目.这是代码

这是Gallery的适配器

这是Bettable布局的代码

Geo*_*zov -3

这是视图回收。尝试使用 ViewHolder 模式并为每个 getView 调用设置项目状态。如果你想这样做,你必须在复杂对象中保存视图状态。例如,您的复杂对象包含 TextView、ImageView 和 CheckBox

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

    ComplexObject co = objects.get(position);

    // A ViewHolder keeps references to children views to avoid unneccessary calls
    // to findViewById() on each row.
    ViewHolder holder;

    // When convertView is not null, we can reuse it directly, there is no need
    // to reinflate it. We only inflate a new View when the convertView supplied
    // by ListView is null.
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.list_item_icon_text, null);

        // Creates a ViewHolder and store references to the two children views
        // we want to bind data to.
        holder = new ViewHolder();
        holder.text = (TextView) convertView.findViewById(R.id.text);
        holder.icon = (ImageView) convertView.findViewById(R.id.icon);
        holder.checkbox = (CheckBox)convertView.findViewById(R.id.checkbox);
        convertView.setTag(holder);
    } else {
        // Get the ViewHolder back to get fast access to the TextView
        // and the ImageView.
        holder = (ViewHolder) convertView.getTag();
    }

    // Bind the data efficiently with the holder.
    holder.text.setText(co.getText());
    holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);
    holder.checkbox.setChecked(co.isChecked());

    holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                    co.setChecked(isChecked);
                }
            });


    return convertView;
}

protected class ViewHolder{
    TextView text;
    ImageView icon;
    CheckBox checkbox; 

}   
Run Code Online (Sandbox Code Playgroud)

希望它会有所帮助