Home  >  Article  >  Java  >  Remember a SwipeMenuListView side sliding deletion disorder bug in Android development

Remember a SwipeMenuListView side sliding deletion disorder bug in Android development

高洛峰
高洛峰Original
2017-01-13 10:05:511451browse

There are many solutions on the Internet for sliding deletion, such as rewriting Listview to monitor sliding. Today we will talk about the next SwipeListView. This is an encapsulated component that was open sourced by a friend on the Internet. It can be applied to a variety of situations. Project address: https://github.com/baoyongzhang/SwipeMenuListView, I also adopted the borrowing principle and used it directly.

But when debugging and running the sliding deletion of data, a problem occurred. The deletion position was wrong. The first data deleted was deleted, but the last one was deleted. So to find the problem, I first tried it with listview. After checking, there is no problem with the data, so it means that the position of the deleted control was calculated incorrectly during deletion. Here are two renderings first.

So what caused the problem? I looked at a previously submitted version (I remember that it was good to use before, indicating that it was a recently submitted problem), so I found a problem, that is, the getview method of the SwipeMenuAdapter class is smaller than before. There is one more judgment, added for caching. I tried to remove the judgment condition and ran it again. Okay, here is some code.

public View getView(int position, View convertView, ViewGroup parent) { 
SwipeMenuLayout layout = null; 
// if (convertView == null) { 
View contentView = mAdapter.getView(position, convertView, parent); 
SwipeMenu menu = new SwipeMenu(mContext); 
menu.setViewType(getItemViewType(position)); 
createMenu(menu); 
SwipeMenuView menuView = new SwipeMenuView(menu, 
(SwipeMenuListView) parent); 
menuView.setOnSwipeItemClickListener(this); 
SwipeMenuListView listView = (SwipeMenuListView) parent; 
layout = new SwipeMenuLayout(contentView, menuView, 
listView.getCloseInterpolator(), 
listView.getOpenInterpolator()); 
layout.setPosition(position); 
// } else { 
// layout = (SwipeMenuLayout) convertView; 
// layout.closeMenu(); 
// layout.setPosition(position); 
//// View view = mAdapter.getView(position, layout.getContentView(), 
//// parent); 
// } 
if (mAdapter instanceof BaseSwipListAdapter) { 
boolean swipEnable = (((BaseSwipListAdapter) mAdapter).getSwipEnableByPosition(position)); 
layout.setSwipEnable(swipEnable); 
} 
return layout; 
}

The above is the Android introduced by the editor. There is a bug in the SwipeMenuListView side sliding deletion during development. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the PHP Chinese website!

For more related articles about a SwipeMenuListView side-sliding deletion bug in Android development, please pay attention to the PHP Chinese website

!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn