示例#1
0
  @Override
  public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    SwipeMenuCreator creator =
        new SwipeMenuCreator() {

          @Override
          public void create(SwipeMenu menu) {
            createMenu(menu);
          }
        };
    // set creator
    mSwipeMenuListView.setMenuCreator(creator);
    mSwipeMenuListView.setOnItemClickListener(this);
    mSwipeMenuListView.setOnMenuItemClickListener(this);
    mSwipeMenuListView.setOnScrollListener(this);

    /** 获取本地数据 */
    getNewsListDataFromLocal(todayTime);

    /** 获取网上数据 */
    getNewsListGsonDataFromNet(false, todayTime);

    hideFootView();

    super.onActivityCreated(savedInstanceState);
  }
示例#2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_bookmark, container, false);

    // Set the adapter
    mListView = (SwipeMenuListView) view.findViewById(android.R.id.list);
    mListView.setAdapter(mAdapter);
    mListView.setMenuCreator(creator);
    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);
    mListView.setOnScrollListener(
        new AbsListView.OnScrollListener() {
          int mLastFirstVisibleItem = 0;

          @Override
          public void onScrollStateChanged(AbsListView view, int scrollState) {}

          @Override
          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (view.getId() == mListView.getId()) {
              final int currentFirstVisibleItem = mListView.getFirstVisiblePosition();

              if (currentFirstVisibleItem > mLastFirstVisibleItem) {
                // getSherlockActivity().getSupportActionBar().hide();
                ((ActionBarActivity) getActivity()).getSupportActionBar().hide();
              } else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
                // getSherlockActivity().getSupportActionBar().show();
                ((ActionBarActivity) getActivity()).getSupportActionBar().show();
              }
              mLastFirstVisibleItem = currentFirstVisibleItem;
            }
          }
        });
    mListView.setOnMenuItemClickListener(
        new SwipeMenuListView.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
            switch (index) {
              case 0:
                // delete
                DB.delOne(data.get(position));
                // Update Home screen product list.
                MyApp.getInstance().updateProductFromWishlist(false, data.get(position).objectId);
                // Update wishlist view
                data = DB.getAllProduct();
                mAdapter = new FavoriteAdapter(getActivity(), data);
                mListView.setAdapter(mAdapter);
                break;
            }
            // false : close the menu; true : not close the menu
            return false;
          }
        });
    mListView.setSwipeDirection(SwipeMenuListView.DIRECTION_LEFT);
    return view;
  }