I am trying to add Animation for ListView I am using getView()to draw some views in list. all works fine.
public View getView(int position, View convertView, ViewGroup parent) { }
I am trying to add animation when user click on list cell then all list cells should slide left and new data should come from right at same time, means cell data is moving towards left and same time new data coming from right side.
I Have implemented following code in OnItemClickListener
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Animation slideOutAnimation=AnimationUtils.loadAnimation(this, R.anim.slide_out);
slideOutAnimation.setDuration(900);
Animation slideInAnimation=AnimationUtils.loadAnimation(this, R.anim.slide_in);
slideInAnimation.setDuration(500);
listView.startAnimation(slideOutAnimation);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
data = newData();
listView.startAnimation(slideInAnimation);
myAdapterClass.notifyDataSetChanged();
}
}, slideOutAnimation.getDuration());
}
};
above code is working but not getting desire output I am getting one empty view while changing Animation.
Left Sliding Animation Starts--- Empty View----Right Sliding Animation Starts
Not getting why Empty view (shows empty screen for while) is coming, I have played with Animation time and handler but no luck.
How to remove that empty view ? how to achieve this output ?
Left Sliding Animation Starts(Data moving)( Same time data coming from Right) Right Sliding Animation Starts
I am trying to add animation when user click on list cell then all list cells should slide left and new data should come from right at same time, means cell data is moving towards left and same time new data coming from right side.
Your code works as intended but it will not do what you want simply because you use a single ListView
widget which you first animate sliding left and then animate sliding right after the first animation ends.
Try to use a ViewFlipper
containing two ListViews
(one will be the visible one the other will be the one that comes with new data). You'll set your animations on the ViewFlipper
(in
and out
animations) and then on a list item click you'll do:
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
data = newData();
//set the data for the second list, which currently isn't visible
secondListViewAdapter.notifyDataSetChanged();
viewFlipper().showNext(); //show the next list with animation
}