戴玛加AndroidSwipeLayout问题

时间:2016-11-29 13:15:36

标签: android

我在Listview中使用该库进行滑动选项。 https://github.com/daimajia/AndroidSwipeLayout

在通过滑动打开项目时,我向下滚动我可以看到其他视图也在特定的层间打开。 我将适配器的模式设置为

Attributes.Mode.Single

任何人都知道为什么会这样?

适配器类

public class FleetListAdapter extends BaseSwipeAdapter {


LayoutInflater layoutInflater;
Context context;
ArrayList<Response> categories;


public FleetListAdapter(Context context, ArrayList<Response> categoriess) {

    this.context = context;
    layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.categories = new ArrayList<>(categoriess);
}

public void UpdateDetails(ArrayList<Response> categoriess) {
    this.categories = new ArrayList<>(categoriess);
    notifyDataSetChanged();

}

@Override
public void setMode(Attributes.Mode mode) {
    super.setMode(mode);
}

@Override
public int getSwipeLayoutResourceId(int position) {
    return R.id.swipe;
}

@Override
public View generateView(int position, ViewGroup parent) {
    View v = layoutInflater.inflate(R.layout.item_vehiclefleet, null);
    SwipeLayout swipeLayout = (SwipeLayout) v.findViewById(getSwipeLayoutResourceId(position));
    swipeLayout.addSwipeListener(new SimpleSwipeListener() {
        @Override
        public void onOpen(SwipeLayout layout) {
            YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.trash));
        }
    });
    v.findViewById(R.id.delete).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(context, "click delete", Toast.LENGTH_SHORT).show();
        }
    });
    return v;
}

@Override
public void fillValues(int position, View convertView) {
    TextView materialEditTextModelNo = (TextView) convertView.findViewById(R.id.itemvehiclefleet_txt_modelno);
    TextView materialEditTextPlateno = (TextView) convertView.findViewById(R.id.itemvehiclefleet_txt_plateno);
    TextView materialEditTextDriver = (TextView) convertView.findViewById(R.id.itemvehiclefleet_txt_driver);

    materialEditTextModelNo.setText(((Response) getItem(position)).getName());
    materialEditTextPlateno.setText(((Response) getItem(position)).getLicensePlate());
    materialEditTextDriver.setText(((Response) getItem(position)).getName());
}


@Override
public int getCount() {
    return  categories.size();
}

@Override
public Object getItem(int position) {
    return categories.get(position);
}

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

}

我正在设置适配器

  FleetListAdapter  fleetListAdapter = new FleetListAdapter(getActivity(), fleetList);

    swipeMenuListView.setAdapter(fleetListAdapter);

    fleetListAdapter.setMode(Attributes.Mode.Single);

1 个答案:

答案 0 :(得分:1)

您可以通过添加

来完成此操作
 swipeMenuListView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            ((BaseSwipeAdapter)fleetListAdapter).closeAllItems();
            Log.e("ListView", "onScrollStateChanged");

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

        }
    });