LoginSignup
3

More than 5 years have passed since last update.

WebViewをpull-to-refreshでちょいハマった

Last updated at Posted at 2016-08-29

case:1

症状

ListViewなんかと同じで
WebViewを素直にSwipeRefreshLayoutで囲うだけで
pull-to-refresh対応できてたのが
レイアウトによって? は、うまく動かなかった。

こんなメッセージが出力されて空振りする。

"Got ACTION_MOVE event but don't have an active pointer id."

落ちたりはしないんだけど
空振り → OK → 空振り、を交互に繰り返すw

対処

WebViewをScrollViewで囲う

layout
前略

<android.support.v4.widget.SwipeRefreshLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <WebView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

    </ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>

その他

Recyclerとか、他のViewでも同様の現象に対応できるのかも。
レイアウトの書き方によっては問題は起きないので
親とか、階層とかに原因がありそう。

とりあえず何かわかったら追記します。

case:2

症状

さぁーて、次の地雷はこちら!

pull-to-refresh して、それの完了前にUI触ってViewPagerのPageを切り替えるとか
そんなタイミングでこれが出て落ちる。

nullオブジェクトさんのフィールドを参照しようとしてあぼ~んのようなので

java.lang.NullPointerException: Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference

対処

そんなオブジェクツさんは消してしまいましょう。
onDestroy()あたりでremoveViewする。

    private SwipeRefreshLayout mRefresh;

    @Override
    public void onDestroy() {
        super.onDestroy();

        if(mRefresh != null) {
            mRefresh.removeAllViews();
        }
    }

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3