androidgalleryview

setting text in Gallery onItemSelected causes scrolling to snap


In the galleryView onItemSelected I call setText that change the text for a textview thats part of the main layout:

@Override
public void onItemSelected(EcoGalleryAdapterView<?> parent, View view, int position, long id) {
     // --- run asyncTask to update gallery view here
     TextView myTextView = (TextView) findViewById(R.id.myTextView);
     myTextView.setText("position is: ": position);
}

if I left everything as it is and just removed myTextView.setText the gallery works as expected but if I kept it then when scrolling the gallery snaps to the selected position really fast in an ugly way. What could be the issue?


Solution

  • "Ugly" is a pretty subjective term for describing a user interface transition.

    However, it sounds as though what you want is a custom animation when an item is selected. onItemSelected() is called before the layout happens, so you can animate your Gallery or individual Views however you want in this method.

    I would suggest reading the Animation and Graphics documentation from the Android developer documentation to more fully understand animations and to help decide what you actually want.

    The code will vary depending on what you decide you want it to look like and what version of Android you are targeting. A simple View animation that will fade the selected view in might look something like this:

    public void onItemSelected(EcoGalleryAdapterView<?> parent, View view, 
            int position, long id) {
        view.setAnimation(new AlphaAnimation(0, 1));
    }