4 개의 항목이있는 FragmentGridPagerAdapter를 표시하려고하는데 뷰가 스크롤되면 항목을 어댑터에 추가하려고합니다. FragmentGridPagerAdapter에 항목을 동적으로 추가합니다.
이
내 FragmentPagerAdapter입니다 :public class MyPagerAdapter extends FragmentGridPagerAdapter {
private final Context _ctx;
private HashMap<Integer, Entry> _data;
public MyPagerAdapter(Context context, FragmentManager fm, HashMap<Integer, Entry> tidatals) {
super(fm);
_ctx = context;
_data = data;
}
public void addEntry(Entry entry)
{
_data.put(_data.size(), entry);
this.notifyDataSetChanged();
}
@Override
public Fragment getFragment(int i, int i2) {
CardFragment fragment = CardFragment.create("Card", _data.get(i).getPrettyText());
fragment.setCardGravity(Gravity.BOTTOM);
fragment.setExpansionEnabled(true);
return fragment;
}
@Override
public int getRowCount() {
return _data.size();
}
@Override
public int getColumnCount(int i) {
return 1;
}
}
그리고 이것은 내 홈페이지 착용 활동에 어댑터에 데이터를 추가하는 방법입니다 : 나는에 항목을 추가
//In onCreate:
_data = new HashMap<Integer, Entry>();
_adapter = new TILPagerAdapter(this, getFragmentManager(), _data);
_pager.setAdapter(_adapter);
//When I finally get my data:
...
// Do stuff, get datas in 'data' variable
MainWear.this.runOnUiThread(new Runnable() {
@Override
public void run() {
boolean firstData = _data.isEmpty();
for(TILEntry entry : data.values())
{
_adapter.addEntry(entry);
}
if(firstData){
_pager.setAdapter(_adapter);
switchViewToResults(); // Sets pager to visible
}
}
});
어댑터 및 호출 notifyDataSetChanged() 어댑터를 새로 고칩니다. 그러나 추가 된 페이지쪽으로 스크롤 할 때 충돌이 발생합니다. getFragment가 호출 될 때
E/InputEventReceiver﹕ Exception dispatching input event.
E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI﹕ java.lang.ArrayIndexOutOfBoundsException: length=4; index=4
at android.support.wearable.view.GridViewPager.populate(GridViewPager.java:873)
at android.support.wearable.view.GridViewPager.setCurrentItemInternal(GridViewPager.java:584)
at android.support.wearable.view.GridViewPager.handlePointerUp(GridViewPager.java:1990)
at android.support.wearable.view.GridViewPager.onTouchEvent(GridViewPager.java:1492)
at android.view.View.dispatchTouchEvent(View.java:7846)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1944)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2215)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1958)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2215)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1958)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2215)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1958)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2215)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1958)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2085)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1532)
at android.app.Activity.dispatchTouchEvent(Activity.java:2468)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2033)
at android.view.View.dispatchPointerEvent(View.java:8026)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3989)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3868)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3433)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3483)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3559)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3460)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3616)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3433)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3483)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3460)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3433)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5589)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5569)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5540)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5669)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:5026)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
D/AndroidRuntime﹕ Shutting down VM
W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xadb04d70)
E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: til.wear.robineisenberg.til_wear, PID: 5808
java.lang.ArrayIndexOutOfBoundsException: length=4; index=4
at android.support.wearable.view.GridViewPager.populate(GridViewPager.java:873)
at android.support.wearable.view.GridViewPager.setCurrentItemInternal(GridViewPager.java:584)
at android.support.wearable.view.GridViewPager.handlePointerUp(GridViewPager.java:1990)
at android.support.wearable.view.GridViewPager.onTouchEvent(GridViewPager.java:1492)
at android.view.View.dispatchTouchEvent(View.java:7846)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1944)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2215)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1958)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2215)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1958)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2215)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1958)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2215)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1958)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2085)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1532)
at android.app.Activity.dispatchTouchEvent(Activity.java:2468)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2033)
at android.view.View.dispatchPointerEvent(View.java:8026)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3989)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3868)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3433)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3483)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3559)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3460)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3616)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3433)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3483)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3460)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3433)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5589)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5569)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5540)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5669)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:5026)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
내가 _data.size는() getFragment가 호출 팔 때 제대로 가치가 _data 내 어댑터의 크기를 인쇄 : 여기
는 스택 트레이스입니다.로그에서 4는 초기 어댑터 크기의 크기입니다. 8은 나중에 원하는 크기입니다. 아이템을 추가 할 때 충돌은 발생하지 않지만 카드를 통해 새로운 아이템을 향해 스크롤 할 때만 충돌합니다. 내가 도대체 뭘 잘못하고있는 겁니까?
편집 : 실제로, 이것은 어댑터의 notifyDataSetChanged 함수에있는 것 같습니다.
this.mRowScrollX[row] = computePageLeft(...);
이 mRowScroll
의 길이 같은데 :
https://code.google.com/p/android/issues/detail?id=73846&thanks=73846&ts=1405945122
가GridViewPager.populate()
에서
나는 이것을해야한다는 것을 싫어하지만 이것은 나를 위해 일했다. 무리 감사! – StackJP