I encountered the following bug : I implemented a ListFragment that displays the content of a table. When I long-click an item, I want to delete the corresponding line in the table and of course to remove the item from the list. To do so, I implemented a setOnItemLongClickListener. It works fine. Now I wanted to make it good-looking, so I added in the listener an animation on the view.
view.animate().setDuration(100).alpha(0)
The result is : when I longclick an item, the one below the one I removed also disappear. I guess the animation is also applied on it. This is a shame. Any idea to solve it or any know-bug related to that ?
Please note I also tried to do it through a Runnable() as below but it doesn't work too
view.animate().setDuration(200).alpha(0).withEndAction(new Runnable() { ... }
You can find my code below :
public class NoteListFragment extends ListFragment {
private NoteListInterface INoteList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
this.getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
INoteList.onEdit(position);
}
});
this.getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
// /!\ RESOLVE ISSUE with animation /!\
view.animate().setDuration(100).alpha(0);
return INoteList.onDelete(position);
/*final int pos = position;
view.animate().setDuration(200).alpha(0).withEndAction(new Runnable() {
@Override
public void run() {
try
{
INoteList.onDelete(pos);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
return true;*/
}
});
}