コード例 #1
0
ファイル: LayoutFragment.java プロジェクト: Kisty/twoway-view
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final Activity activity = getActivity();

    mToast = Toast.makeText(activity, "", Toast.LENGTH_SHORT);
    mToast.setGravity(Gravity.CENTER, 0, 0);

    mRecyclerView = (TwoWayView) view.findViewById(R.id.list);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLongClickable(true);

    mPositionText = (TextView) view.getRootView().findViewById(R.id.position);
    mCountText = (TextView) view.getRootView().findViewById(R.id.count);

    mStateText = (TextView) view.getRootView().findViewById(R.id.state);
    updateState(SCROLL_STATE_IDLE);

    final ItemClickSupport itemClick = ItemClickSupport.addTo(mRecyclerView);

    itemClick.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(RecyclerView parent, View child, int position, long id) {
            mToast.setText("Item clicked: " + position);
            mToast.show();
          }
        });

    itemClick.setOnItemLongClickListener(
        new OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(RecyclerView parent, View child, int position, long id) {
            mToast.setText("Item long pressed: " + position);
            mToast.show();
            return true;
          }
        });

    mRecyclerView.setOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(int scrollState) {
            updateState(scrollState);
          }

          @Override
          public void onScrolled(int i, int i2) {
            mPositionText.setText("First: " + mRecyclerView.getFirstVisiblePosition());
            mCountText.setText("Count: " + mRecyclerView.getChildCount());
          }
        });

    final Drawable divider = getResources().getDrawable(R.drawable.divider);
    mRecyclerView.addItemDecoration(new DividerItemDecoration(divider));

    mRecyclerView.setAdapter(new SimpleAdapter(activity, mRecyclerView, mLayoutId));
  }
コード例 #2
0
ファイル: Calender.java プロジェクト: dhruv2295/NSIT-App-v2
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_calender, container, false);
    lvTest = (TwoWayView) rootView.findViewById(R.id.lvItems);
    if (activity == null) return rootView;

    s = PreferenceManager.getDefaultSharedPreferences(activity);
    e = s.edit();
    Boolean b = s.getBoolean(IS_CLASS_SET, false);
    if (!b) {
      Intent i = new Intent(activity, ChooseClass.class);
      startActivity(i);
    }

    Boolean a = s.getBoolean(IS_TIME_TABLE_CHANGED, true);
    timetable = s.getString(GET_TIME_TABLE, null);

    adapter2 = new CustomList_calendar(activity, days, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
    lvTest.setAdapter(adapter2);
    lvTest.setItemMargin(10);

    if (a == true || timetable == null) {
      if (Utils.isNetworkAvailable(activity)) new DownloadWebPageTask2().execute();
      else {
        SnackbarManager.show(
            Snackbar.with(activity.getApplicationContext())
                .text("Check Your Internet Connection")
                .duration(Snackbar.SnackbarDuration.LENGTH_SHORT),
            activity);
      }
    } else {
      load();
    }

    lvTest.setOnScrollListener(
        new TwoWayView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(TwoWayView view, int scrollState) {}

          @Override
          public void onScroll(
              TwoWayView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            int lastInScreen = firstVisibleItem + visibleItemCount;
            if ((lastInScreen == totalItemCount) && !(loadingMore)) {
              load();
            }
            adapter2.notifyDataSetChanged();
          }
        });
    return rootView;
  }