Domanda

I have this ListView that fetches friends from Facebook:

@Override
        public void onComplete(List<Profile> friends) {

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mSpinner.setVisibility(View.GONE);
                    mSpinner.clearAnimation();
                }
                });

            // populate list
            List<String> values = new ArrayList<String>();
            for (Profile profile : friends) {
                values.add(profile.getName());
            }



            ArrayAdapter<String> friendsListAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_items2, values);
            friendsListAdapter.sort(new Comparator<String>() {
                @Override
                public int compare(String lhs, String rhs) {
                    return lhs.compareTo(rhs);    
                }
            });
            mFriendsList.setAdapter(friendsListAdapter);
        }
    };

And i have this animation xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">
 <translate android:fromXDelta="100%p" android:toXDelta="0"
     android:duration="300"/>
   <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
     android:duration="300" />
</set>

I have tried looking for examples on how to add animation to the ListView, but i couldn't get them to work with my code, what i wish to create is that when an item inside the ListView is clicked, it starts the animation. How could i add this to my code using OnItemClick?

È stato utile?

Soluzione

You can use the view that is inside the onclick and use the to animate when one of the listView is clicked:

     listView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> av, final View view, final int i, long i2) {

                  Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.YOUR_ANIMATION);
                  view.startAnimation(hyperspaceJumpAnimation);

            }
            });
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top