emilsjolander / android-FlipView

A small, easy to use android library for implementing flipping between views as seen in the popular Flipboard application
Apache License 2.0
924 stars 273 forks source link

Can't make it work with a SimpleCursorAdapter #31

Open Michenux opened 10 years ago

Michenux commented 10 years ago

Hi,

I can't make it work with a SimpleCursorAdapter. I got a nullpointerexception

java.lang.NullPointerException at SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:118) at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:256) at se.emilsjolander.flipview.FlipView.getView(FlipView.java:417) at se.emilsjolander.flipview.FlipView.fillPageForIndex(FlipView.java:382) at se.emilsjolander.flipview.FlipView.setFlipDistance(FlipView.java:367) at se.emilsjolander.flipview.FlipView.flipTo(FlipView.java:1124) at se.emilsjolander.flipview.FlipView.dataSetChanged(FlipView.java:226) at se.emilsjolander.flipview.FlipView.access$000(FlipView.java:33) at se.emilsjolander.flipview.FlipView$1.onChanged(FlipView.java:86) at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37) at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50) at android.support.v4.widget.CursorAdapter.swapCursor(CursorAdapter.java:347)

The "from" in the SimpleCursorAdapter is null. It works well when i use a ListView instead of FlipView.

emilsjolander commented 10 years ago

Could you please post the code you use the create and set the SimpleCursorAdapter?

Michenux commented 10 years ago

I initialize the adapter like this (in the onCreateView of my fragment) :

this.mAdapter = new SimpleCursorAdapter(this.getActivity(), R.layout.page, null, mAdapterFromColumns, mAdapterToViews, 0);

And when in the method onLoadFinished :

public void onLoadFinished(Loader loader, Cursor cursor) { this.mAdapter.changeCursor(cursor); }

This method doesnot work with the FlipView (works with a listView)

I found a workaround, i delay the creation of the adapter :

@Override public void onLoadFinished(Loader loader, Cursor cursor) {

    if ( this.mAdapter == null ) {
        this.mAdapter = new SimpleCursorAdapter(this.getActivity(),
            R.layout.page, cursor, mAdapterFromColumns,

mAdapterToViews, 0); this.mAdapter.setViewBinder(this); mFlipView.setAdapter(this.mAdapter); } else { this.mAdapter.changeCursor(cursor); } }

2014/1/26 Emil Sjölander notifications@github.com

Could you please post the code you use the create and set the SimpleCursorAdapter?

— Reply to this email directly or view it on GitHubhttps://github.com/emilsjolander/android-FlipView/issues/31#issuecomment-33316231 .

emilsjolander commented 10 years ago

What android version are you seeing this on?

Michenux commented 10 years ago

4.4

2014/1/26 Emil Sjölander notifications@github.com

What android version are you seeing this on?

— Reply to this email directly or view it on GitHubhttps://github.com/emilsjolander/android-FlipView/issues/31#issuecomment-33319288 .

emilsjolander commented 10 years ago

Looking up the source for SimpleCursorAdapter there are just comments on line 118 making it hard to track down what is actually happening.