For prettier formatting of this message, this question has been posted
on StackOverflow - http://stackoverflow.com/q/9490558/974800 . I am
posting here due to a lack of response there.

I am writing an app that has a couple of fragment views managed by an
activity. The fragments are basically a GridView with a bunch of
images and a details view that is triggered when the user clicks on an
image in the GridView.

This all works fine, except that since there is a lot of other stuff
going from the activity to the grid fragment (I am continuously adding
things to the grid view and displaying them immediately), it takes
several seconds for the click to be recognized. I had assumed that
building the image would be the time-consuming bit, and that when I
click the item, that that event should be sent to the activity
immediately, since there isn't any heavy lifting involved. Once the
message gets to the activity, the activity will stop updating the grid
view, and work on building the details view.

The issue here is that clicking an element in the grid view is taking
several seconds (5 to 10 on a slower phone) to register. What do I
need to do to speed this action up?

Relevant GridFragment code:

public class GridFragment extends Fragment{
...
public class ImageAdapter extends BaseAdapter  {
    private GridContent gridContent;
    private Context mContext;

    ...
    public View getView(final int position, View convertView,
ViewGroup parent) {
        // ImageView is my private holder class
        ImageView imageView;
        imageView = new ImageView(mContext);
 
imageView.setImageBitmap(gridContent.get(position).getThumb());

        imageView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                // This is what I expect to see immediately upon
clicking something,
                //  but takes several seconds to show up in logcat
                if (Constants.DEBUG){ Log.d(TAG, "an item was clicked
- "
                    + gridContent.get(position).getId());}
                    //mListener is a listener implemented by my
activity
                    // gridContent.get(position) just returns a small
object,
                    //  it shouldn't be doing much work
 
mListener.onItemSelected(gridContent.get(position));
            }

          });

        return imageView;
    }
}
}

Relevant Activity code:

@Override
public void onItemSelected(Item item) {
    // Displays a loading dialog
    showLoadDialog();
    Item pi = item;
    // This builds an image from the web, it might be slow depending
on the
    //  phone's connection
    pi.genImage();
    FragmentTransaction ft =
getSupportFragmentManager().beginTransaction();
    hideLoadDialog();
    ft.addToBackStack(Constants.DETAILS_STACK)
    .add(android.R.id.content, DetailsFragment.newInstance(0,pi))
    .commit();
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to