2014-07-14 5 views
4

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()에서

답변

3

라인 873은 이것이다 : 나는 당신이 고정 될 필요가 생각한다면 구글이 그것을 스타 승/버그 리포트를 열 배열은 어댑터를 설정할 때 고정되며 notifyDataSetChanged()이 실행될 때 getRowCount()에서 업데이트되지 않습니다. 나는 이것이 호출하여 우회 할 수 GridViewPager 버그, 생각하는 것, 한마디로

this.mExpectedRowCount = this.mAdapter.getRowCount(); 
    this.mRowScrollX = new int[this.mExpectedRowCount]; 

: 당신이 GridViewPager 클래스의 나머지 부분을 확인하면 실제로, 당신은 그것을에만 setAdapter() 방법에 할당 된 것 볼 수 있습니다 행 또는 열 수를 업데이트 할 때마다 다시 setAdapter()을 입력하십시오.

+0

나는 이것을해야한다는 것을 싫어하지만 이것은 나를 위해 일했다. 무리 감사! – StackJP

1

이 버그는 최신 Android Wear 5.0 릴리스와 함께 제공된 최신 착용 가능 지원 라이브러리 1.1에서 수정되었을 것입니다.

+0

그냥 LG-G Watch에서 저에게 해 봤습니다. 정보 주셔서 감사합니다. 그냥 빠른 질문 :이 문제에 대해 제출 한 버그 보고서가 "해결 된"것으로 표시되지 않는 것이 정상입니까? 이 경우 게시해야하는 다른 이슈 트래커가 있습니까? –