Question

I have a custom CursorAdapter which I'm using to inflate a custom item layout and style accordingly, as shown in the code below. My issue is that sometimes the wrong style information is supplied even though the data coming from the DB is correct (so for the below example I'll get isEvent == true but it'll go on to style as if isEvent == false.

Is this a known bug? Am I doing something wrong or is there something I can do which will fix this?

private class EventAdapter extends CursorAdapter {
    public EventAdapter(Context context) {
        super(context, null);
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        return getLayoutInflater().inflate(R.layout.event_view_list_item, parent, false);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        final boolean isEvent = cursor.getInt(EventQuery.IS_EVENT) == Event.EVENT;
        final String eventName = cursor.getString(EventQuery.NAME);
        final TextView eventNameView = (TextView) view.findViewById(R.id.event_name);

        if (isEvent) {
            eventNameView.setText(eventName);
            view.findViewById(R.id.arrow).setVisibility(View.VISIBLE);
            view.findViewById(R.id.in_play_icon).setVisibility(View.GONE);
        } else {
            eventNameView.setText(cursor.getString(EventQuery.NAME));
        }
    }
}
Was it helpful?

Solution

I think this is just a case of the old issue of Android reusing views. By resetting the view and replacing where appropriate this can be fixed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top