AndroidリストビューのAsyncTaskに問題があるのは、正常に実行されている場合は実際には問題ではないため、非同期タスクの実行中にユーザーがページを次のページにスクロールすると、強制の直接適用が閉じられます。
私はすべての条件を次のように試しました:
if (AsyncTask.Status.RUNNING == null) {
/ / My code do in backgroud here
}
if (backgroundtask.getStatus! = STATUS.RUNNING) {
/ / My code do in backgroud here
}
いつも失敗…
public abstract View getAmazingView(int position, View convertView,
ViewGroup parent);
public final View getView(int position, View convertView, ViewGroup parent) {
View res = getAmazingView(position, convertView, parent);
if (position == getCount() - 1 && automaticNextPageLoading) {
onNextPageRequested(page + 1);
}
final int section = getSectionForPosition(position);
boolean displaySectionHeaders = (getPositionForSection(section) == position);
bindSectionHeader(res, position, displaySectionHeaders);
return res;
}
protected void onNextPageRequested(int page) {
backgroundTask = new AsyncTask<Integer, Void, List<Bola>>() {
protected List<Bola> doInBackground(
Integer... params) {
int page = params[0];
return Adapter.getRows(page);
}
protected void onPostExecute(
List<Bola> result) {
if (isCancelled()){
backgroundTask.cancel(true);
}
list.addAll(result);
nextPage();
notifyDataSetChanged();
if (result.size() > 0) {
// still have more pages
notifyMayHaveMorePages();
} else {
notifyNoMorePages();
}
};
}.execute(page);
}
AsyncTask 実行条件でどのように実行でき、ユーザーはスクロール ダウン イベントを使用しますか?
======= 私のログを更新 =======
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): FATAL EXCEPTION: main
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131034281, class com.dhika.bola.application.ui.ListUtils) with Adapter(class android.widget.HeaderViewListAdapter)]
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.widget.ListView.layoutChildren(ListView.java:1548)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.widget.AbsListView.onTouchEvent(AbsListView.java:3490)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at com.dhika.bola.application.ui.ListUtils.onTouchEvent(ListUtils.java:445)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.View.dispatchTouchEvent(View.java:7262)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2235)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1932)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2241)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2241)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2241)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2241)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2241)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1968)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1420)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.app.Activity.dispatchTouchEvent(Activity.java:2428)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1916)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.View.dispatchPointerEvent(View.java:7442)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3610)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3538)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4790)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4750)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4902)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:171)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4870)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4924)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.Choreographer.doCallbacks(Choreographer.java:579)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.Choreographer.doFrame(Choreographer.java:546)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.os.Handler.handleCallback(Handler.java:725)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.os.Handler.dispatchMessage(Handler.java:92)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.os.Looper.loop(Looper.java:153)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at android.app.ActivityThread.main(ActivityThread.java:5297)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at java.lang.reflect.Method.invokeNative(Native Method)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at java.lang.reflect.Method.invoke(Method.java:511)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
11-02 23:22:42.330: ERROR/AndroidRuntime(25830): at dalvik.system.NativeStart.main(Native Method)