@Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Map<String, String> map = mLocalMusicAdapter.getItem(position);
    // 取得铃声名
    String ringName = map.get(WeacConstants.RING_NAME);
    // 取得播放地址
    String ringUrl = map.get(WeacConstants.RING_URL);
    // 更新当前铃声选中的位置
    mLocalMusicAdapter.updateSelection(ringName);
    // 更新适配器刷新铃声列表显示
    mLocalMusicAdapter.notifyDataSetChanged();
    // 设置最后一次选中的铃声选择界面位置为本地音乐界面
    RingSelectItem.getInstance().setRingPager(1);

    // 播放音频文件
    AudioPlayer.getInstance(getActivity()).play(ringUrl, false, false);

    ViewPager pager = (ViewPager) getActivity().findViewById(R.id.fragment_ring_select_sort);
    PagerAdapter f = pager.getAdapter();
    SystemRingFragment systemRingFragment = (SystemRingFragment) f.instantiateItem(pager, 0);
    RecorderFragment recorderFragment = (RecorderFragment) f.instantiateItem(pager, 2);
    // 取消系统铃声选中标记
    if (systemRingFragment.mSystemRingAdapter != null) {
      systemRingFragment.mSystemRingAdapter.updateSelection("");
      systemRingFragment.mSystemRingAdapter.notifyDataSetChanged();
    }
    // 取消录音选中标记
    if (recorderFragment.mRecorderAdapter != null) {
      recorderFragment.mRecorderAdapter.updateSelection("");
      recorderFragment.mRecorderAdapter.notifyDataSetChanged();
    }
  }
 @Override
 public Object instantiateItem(ViewGroup container, int position) {
   if (position == 0) {
     return wrappedAdapter.instantiateItem(container, wrappedAdapter.getCount() - 1);
   } else if (position == wrappedAdapter.getCount() + 1) {
     return wrappedAdapter.instantiateItem(container, 0);
   } else {
     return wrappedAdapter.instantiateItem(container, position - 1);
   }
 }
Ejemplo n.º 3
0
  @Override
  public Object instantiateItem(ViewGroup container, int position) {
    int virtualPosition = position % getRealCount();
    debug("instantiateItem: real position: " + position);
    debug("instantiateItem: virtual position: " + virtualPosition);

    // only expose virtual position to the inner adapter
    return adapter.instantiateItem(container, virtualPosition);
  }
  /** 重新获取嵌套的内容视图 */
  private void regetNestedContentView() {
    int currentItem = mDirectViewPager.getCurrentItem();
    PagerAdapter adapter = mDirectViewPager.getAdapter();
    if (adapter instanceof FragmentPagerAdapter || adapter instanceof FragmentStatePagerAdapter) {
      Fragment item = (Fragment) adapter.instantiateItem(mDirectViewPager, currentItem);
      mNestedContentView = item.getView();

      // 清空之前的
      mNestedNormalView = null;
      mNestedAbsListView = null;
      mNestedRecyclerView = null;
      mNestedScrollView = null;
      mNestedWebView = null;

      if (mNestedContentView instanceof AbsListView) {
        mNestedAbsListView = (AbsListView) mNestedContentView;
        mNestedAbsListView.setOnScrollListener(mLvOnScrollListener);

        if (!isHeaderViewCompleteInvisible()) {
          mNestedAbsListView.setSelection(0);
        }
      } else if (mNestedContentView instanceof RecyclerView) {
        mNestedRecyclerView = (RecyclerView) mNestedContentView;
        mNestedRecyclerView.removeOnScrollListener(mRvOnScrollListener);
        mNestedRecyclerView.addOnScrollListener(mRvOnScrollListener);

        if (!isHeaderViewCompleteInvisible()) {
          mNestedRecyclerView.scrollToPosition(0);
        }
      } else if (mNestedContentView instanceof ScrollView) {
        mNestedScrollView = (ScrollView) mNestedContentView;

        if (!isHeaderViewCompleteInvisible()) {
          mNestedScrollView.scrollTo(mNestedScrollView.getScrollX(), 0);
        }
      } else if (mNestedContentView instanceof WebView) {
        mNestedWebView = (WebView) mNestedContentView;

        if (!isHeaderViewCompleteInvisible()) {
          mNestedWebView.scrollTo(mNestedWebView.getScrollX(), 0);
        }
      } else {
        mNestedNormalView = mNestedContentView;
      }
    } else {
      throw new IllegalStateException(
          BGAStickyNavLayout.class.getSimpleName()
              + "的第三个子控件为ViewPager时,其adapter必须是FragmentPagerAdapter或者FragmentStatePagerAdapter");
    }
  }
    @Override
    void showDetail(int position) {
      clearMultiChoice();
      detailEmptyView.setVisibility(View.GONE);
      detailSource.startUpdate(detailTarget);

      if (lastPosition > -1) {
        detailSource.destroyItem(detailTarget, lastPosition, handle);
      }

      lastPosition = position;

      handle = detailSource.instantiateItem(detailTarget, position);
      detailSource.finishUpdate(detailTarget);
    }
  @Override
  public Object instantiateItem(ViewGroup container, int position) {
    int realPosition =
        (mAdapter instanceof FragmentPagerAdapter || mAdapter instanceof FragmentStatePagerAdapter)
            ? position
            : toRealPosition(position);

    if (mBoundaryCaching) {
      ToDestroy toDestroy = mToDestroy.get(position);
      if (toDestroy != null) {
        mToDestroy.remove(position);
        return toDestroy.object;
      }
    }
    return mAdapter.instantiateItem(container, realPosition);
  }