Java Code Examples for android.support.v7.widget.RecyclerView#addOnItemTouchListener()
The following examples show how to use
android.support.v7.widget.RecyclerView#addOnItemTouchListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From Hacktoberfest with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mRecyclerView = (RecyclerView) findViewById(R.id.book_list_rcv); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mTextViewMsg = (TextView_Lato) findViewById(R.id.message); MaterialSearchBar searchBar = (MaterialSearchBar) findViewById(R.id.searchBar); searchBar.setHint(getString(R.string.book_hint_name)); //enable searchbar callbacks searchBar.setOnSearchActionListener(this); mRecyclerView.setAdapter(mBookListAdapter = new BookListAdapter(mBookArrayList)); mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Toast.makeText(MainActivity.this, mBookListAdapter.getItem(position).toString(), Toast.LENGTH_SHORT).show(); } })); }
Example 2
Source File: CatalogListActivity.java From android-migrate-to-jobs with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_catalog_list); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); inject(); mBus.postActivityCreated(); mCatalogList = (RecyclerView) findViewById(R.id.catalog_list); mCatalogList.setLayoutManager(new LinearLayoutManager(this)); mCatalogList.setAdapter(mAdaptor); mCatalogList.addOnItemTouchListener(new OnCatalogItemTouchListener()); }
Example 3
Source File: MainActivity.java From packagehunter with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); packageHunter = new PackageHunter(this); RecyclerView rv = (RecyclerView) findViewById(R.id.rv_pkglist); pkgInfoArrayList = packageHunter.getInstalledPackages(); adapter = new RVMainAdapter(this, pkgInfoArrayList); rv.hasFixedSize(); rv.setLayoutManager(new LinearLayoutManager(this)); rv.setAdapter(adapter); // Set On Click rv.addOnItemTouchListener( new RVItemClickListener(this, new RVItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Intent i = new Intent(MainActivity.this, DetailActivity.class); i.putExtra("data", pkgInfoArrayList.get(position).getPackageName()); startActivity(i); overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); } })); }
Example 4
Source File: ArcaSimpleRecyclerViewFragment.java From arca-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final View view = inflater.inflate(FragmentUtils.getFragmentLayout(this.getClass()), container, false); final RecyclerView recyclerView = (RecyclerView) view.findViewById(getRecyclerViewId()); recyclerView.addOnItemTouchListener(new RecyclerItemClick(getActivity(), recyclerView, this)); return view; }
Example 5
Source File: TangramEngine.java From Tangram-Android with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public void bindView(@NonNull RecyclerView view) { super.bindView(view); mSwipeItemTouchListener = new SwipeItemTouchListener(view.getContext(), mGroupBasicAdapter, getContentView()); if (mSwipeCardActionEdge != -1) { mSwipeItemTouchListener.setActionEdge(mSwipeCardActionEdge); } view.addOnItemTouchListener(mSwipeItemTouchListener); view.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (recyclerView != null) { scrolledY += dy; } } }); }
Example 6
Source File: QuizCategoryActivity.java From Hillffair17 with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz_category); progressBar = (ProgressBar) findViewById(R.id.category_progress); toolbar = (Toolbar) findViewById(R.id.category_toolbar); recyclerView = (RecyclerView) findViewById(R.id.category_recycler); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); progressBar.setVisibility(View.VISIBLE); layoutManager = new LinearLayoutManager(getApplicationContext()); recyclerView.setLayoutManager(layoutManager); recyclerView.setHasFixedSize(true); recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Intent i=new Intent(QuizCategoryActivity.this,QuizSubCategoryActivity.class); i.putExtra("Category_Name",categories.get(position).getName()); startActivity(i); } })); getCategories(); }
Example 7
Source File: BattleDayActivity.java From Hillffair17 with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { SharedPref pref= new SharedPref(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_event); Toolbar toolbar= (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); recyclerView=(RecyclerView)findViewById(R.id.recycler_view); LinearLayoutManager manager=new LinearLayoutManager(BattleDayActivity.this); recyclerView.setLayoutManager(manager); adapter=new BattleDayAdapter(BattleDayActivity.this); recyclerView.setAdapter(adapter); bar=(ProgressBar)findViewById(R.id.progress); recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Intent i=new Intent(BattleDayActivity.this,ClubActivity.class); i.putExtra("name",list.get(position).getName()); i.putExtra("id",list.get(position).getId()); i.putExtra("battleday",true); startActivity(i); } })); bar.setVisibility(View.VISIBLE); retrofit(); }
Example 8
Source File: EventActivity.java From Hillffair17 with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { SharedPref pref= new SharedPref(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_event); Toolbar toolbar= (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); recyclerView = (RecyclerView) findViewById(R.id.recycler_view); progressBar= (ProgressBar) findViewById(R.id.progress); adapter=new ClubEventAdapter(this); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new GridLayoutManager(this,2)); recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Intent i=new Intent(EventActivity.this,ClubActivity.class); i.putExtra(CLUB_ID,list.get(position).getId()); startActivity(i); } })); showData(); }
Example 9
Source File: QuizSubCategoryActivity.java From Hillffair17 with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz_sub_category); Intent i1 = this.getIntent(); if(i1!=null) { categoryname = i1.getExtras().getString("Category_Name"); } progressBar = (ProgressBar) findViewById(R.id.subcategory_progress); toolbar = (Toolbar) findViewById(R.id.subcategory_toolbar); recyclerView = (RecyclerView) findViewById(R.id.subcategory_recycler); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); progressBar.setVisibility(View.VISIBLE); layoutManager = new LinearLayoutManager(getApplicationContext()); recyclerView.setLayoutManager(layoutManager); recyclerView.setHasFixedSize(true); recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Intent i = new Intent(getApplicationContext(),QuizActivity.class); i.putExtra("Category_Name",subcategories.get(position).getCategory()); i.putExtra("Topic_Name",subcategories.get(position).getName()); startActivity(i); } })); getsubcategory(); }
Example 10
Source File: PickArrivalTimeDialog.java From FastWaiMai with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_settle_arrival_time); mTvArrivalTimeTitle = (TextView) findViewById(R.id.tv_arrival_time_title); mTvArrivalTimeToady = (TextView) findViewById(R.id.tv_arrival_time_toady); mTvArrivalTimeTomorrow = (TextView) findViewById(R.id.tv_arrival_time_tomorrow); mRvArrivalTime = (RecyclerView) findViewById(R.id.rv_arrival_time); mCancleButton = (Button) findViewById(R.id.bt_cancle); mTvArrivalTimeToady.setText(DateUtil.getWeek()); mTvArrivalTimeTomorrow.setText(DateUtil.getWeek(1)); mCancleButton.setOnClickListener(this); mTvArrivalTimeTomorrow.setOnClickListener(this); mTvArrivalTimeToady.setOnClickListener(this); initTodayArrivalTime(); initTomorrowArrivalTime(); final Window window = getWindow(); if(window != null){ window.setGravity(Gravity.BOTTOM); window.setWindowAnimations(R.style.anim_panel_up_from_bottom); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); //设置属性 final WindowManager.LayoutParams params = window.getAttributes(); params.width = WindowManager.LayoutParams.MATCH_PARENT; //FLAG_DIM_BEHIND: 窗口之后的内容变暗 FLAG_BLUR_BEHIND: 窗口之后的内容变模糊。 params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND; window.setAttributes(params); } adapter = new ArrivalTimeAdapter(todayEntities); mRvArrivalTime.setAdapter(adapter); final LinearLayoutManager manager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false); mRvArrivalTime.setLayoutManager(manager); mRvArrivalTime.addOnItemTouchListener(listener); }
Example 11
Source File: BasicAdapter.java From basic-adapter with MIT License | 5 votes |
public void setOnItemClickListener(RecyclerView recyclerView, OnItemClickListener onItemClickListener) { mOnItemClickListener = onItemClickListener; recyclerView.addOnItemTouchListener(new OnRecyclerItemClickListener(recyclerView) { @Override public void onItemClick(ViewHolder vh) { int realPosition = vh.getAdapterPosition() - 1; boolean oldValue; BaseViewHolder holder = (BaseViewHolder) vh; if (vh.getItemViewType() == NORMAL_VIEW) { if (mParams.choiceMode == BasicController.CHOICE_MODE_SINGLE) { oldValue = mCheckStates.get(realPosition); if (!oldValue) { //not checked -> checked clearChoices(); mCheckStates.put(realPosition, true); notifyDataSetChanged(); } else { // checked -> not checked mCheckStates.put(realPosition, false); holder.setChecked(mParams.checkId, false); } } else if (mParams.choiceMode == BasicController.CHOICE_MODE_MULTIPLE) { oldValue = mCheckStates.get(realPosition); mCheckStates.put(realPosition, !oldValue); // notifyDataSetChanged(); holder.setChecked(mParams.checkId, !oldValue); } if (mOnItemClickListener != null) { mOnItemClickListener.onItemClick((BaseViewHolder) vh, realPosition); } } } }); }
Example 12
Source File: ItemSelectionSupport.java From UltimateAndroid with Apache License 2.0 | 4 votes |
private ItemSelectionSupport(RecyclerView recyclerView) { mRecyclerView = recyclerView; mTouchListener = new TouchListener(recyclerView); recyclerView.addOnItemTouchListener(mTouchListener); }
Example 13
Source File: MainActivity.java From DragSortRecycler with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { final String TAG = "MainActivity"; super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView) findViewById(R.id.recyclerView); final ArrayList<Integer> items = new ArrayList<>(); for (int n=0;n<100;n++) { items.add(n); } final CustomAdapter adapter = new CustomAdapter(items,this); // adapter.setHasStableIds(true); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager( new LinearLayoutManager(this)); recyclerView.setItemAnimator(null); DragSortRecycler dragSortRecycler = new DragSortRecycler(); dragSortRecycler.setViewHandleId(R.id.imageView); dragSortRecycler.setFloatingAlpha(0.4f); dragSortRecycler.setFloatingBgColor(0x800000FF); dragSortRecycler.setAutoScrollSpeed(0.3f); dragSortRecycler.setAutoScrollWindow(0.1f); dragSortRecycler.setOnItemMovedListener(new DragSortRecycler.OnItemMovedListener() { @Override public void onItemMoved(int from, int to) { Log.d(TAG, "onItemMoved " + from + " to " + to); Integer item = items.remove(from); items.add(to, item); adapter.notifyDataSetChanged(); //notifyItemMoved does work, but it makes the list scroll pos jump a little when dragging near the top or bottom //adapter.notifyItemMoved(from,to); } }); dragSortRecycler.setOnDragStateChangedListener(new DragSortRecycler.OnDragStateChangedListener() { @Override public void onDragStart() { Log.d(TAG, "Drag Start"); } @Override public void onDragStop() { Log.d(TAG, "Drag Stop"); } }); recyclerView.addItemDecoration(dragSortRecycler); recyclerView.addOnItemTouchListener(dragSortRecycler); recyclerView.setOnScrollListener(dragSortRecycler.getScrollListener()); }
Example 14
Source File: CalendarFragment.java From narrate-android with Apache License 2.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRoot = inflater.inflate(R.layout.fragment_calendar, container, false); // header views if ( mLandscape ) { mHeaderLayout = (LinearLayout) View.inflate(getActivity(), R.layout.calendar_toolbar_view, null); mToolbarTextView = (TextView) mHeaderLayout.findViewById(R.id.cal_header_text); mHeaderLayout.setOnClickListener(this); int position = 0; for ( position = 0; position < mainActivity.mViewPagerOrder.length; position++ ) if ( mainActivity.mViewPagerOrder[position].equals(TAG) ) break; if ( mainActivity.mViewPager.getCurrentItem() == position ) { LinearLayout toolbar = (LinearLayout) mainActivity.getSupportActionBar().getCustomView(); toolbar.addView(mHeaderLayout); mAddedToolbarView = true; } } else { mDayHeaderView = (TextView) findViewById(R.id.cal_header_day); mDayOfWeekHeaderView = (TextView) findViewById(R.id.cal_header_day_of_week); mMonthYearHeaderView = (TextView) findViewById(R.id.cal_header_month_year); findViewById(R.id.cal_header_month_layout).setOnClickListener(this); } // main content view mAnimator = (AccessibleDateAnimator) findViewById(R.id.animator); mDayPickerView = new SimpleDayPickerView(getActivity(), this); mMonthPickerView = new MonthPickerView(getActivity(), this); mYearPickerView = new YearPickerView(getActivity(), this); mDayPickerView.setStickyDisplaySelectedDate(true); if ( !mLandscape ) { mDayPickerView.setFixedHeight(getResources().getDimensionPixelOffset(R.dimen.calendar_height)); } int calColor = getResources().getColor(R.color.section_calendar); int r = Color.red(calColor); int g = Color.green(calColor); int b = Color.blue(calColor); mDayPickerView.setSelectedColor(Color.argb(0x59, r, g, b)); mMonthPickerView.setSelectionColor(Color.argb(0x59, r, g, b)); mYearPickerView.setSelectionColor(Color.argb(0x59, r, g, b)); mYearPickerView.useRectangleSelector(true); mDayPickerView.setTodayColor(Color.BLACK); mDayPickerView.setDayPickerListener(this); mAnimator.addView(mDayPickerView); mAnimator.addView(mMonthPickerView); mAnimator.addView(mYearPickerView); mDayPickerView.setSelected(true); mMonthPickerView.setSelected(false); mYearPickerView.setSelected(false); mAnimator.setDateMillis(mCalendar.getTimeInMillis()); Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(ANIMATION_DURATION); mAnimator.setInAnimation(animation); Animation animation2 = new AlphaAnimation(1.0f, 0.0f); animation2.setDuration(ANIMATION_DURATION); mAnimator.setOutAnimation(animation2); // list view mRecyclerView = (RecyclerView) findViewById(R.id.list); mLinearLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLinearLayoutManager); mRecyclerView.setHasFixedSize(true); mRecyclerView.addOnItemTouchListener(this); mAdapter = new EntriesRecyclerAdapter(mDisplayedEntries); mRecyclerView.setAdapter(mAdapter); mItemAnimator = new ScaleInOutItemAnimator(mRecyclerView); mRecyclerView.setItemAnimator(mItemAnimator); updateDisplay(); updatePickers(); return mRoot; }
Example 15
Source File: ItemClickSupport.java From MultiView with Apache License 2.0 | 4 votes |
private ItemClickSupport(RecyclerView recyclerView) { mRecyclerView = recyclerView; mTouchListener = new TouchListener(recyclerView); recyclerView.addOnItemTouchListener(mTouchListener); }
Example 16
Source File: IssuersActivity.java From px-android with MIT License | 4 votes |
private void initializeAdapterListener(final RecyclerView.Adapter adapter, final RecyclerView view) { view.setAdapter(adapter); view.setLayoutManager(new LinearLayoutManager(this)); view.addOnItemTouchListener(new RecyclerItemClickListener(this, (view1, position) -> presenter.onItemSelected(position))); }
Example 17
Source File: ItemClickSupport.java From Mover with Apache License 2.0 | 4 votes |
private ItemClickSupport(RecyclerView recyclerView) { mRecyclerView = recyclerView; mTouchListener = new TouchListener(recyclerView); recyclerView.addOnItemTouchListener(mTouchListener); }
Example 18
Source File: RecyclerViewUtils.java From PowerfulRecyclerView with Apache License 2.0 | 4 votes |
public void addOnItemTouchListener(RecyclerView recyclerView,final View recyclerViewHeader){ recyclerView.addOnItemTouchListener(new MyOnItemTouchListener(recyclerViewHeader)); }
Example 19
Source File: MainActivity.java From basic-adapter with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View header = View.inflate(this,R.layout.header,null); View header2 = View.inflate(this,R.layout.header2,null); View footer = View.inflate(this,R.layout.footer,null); View loading = View.inflate(this,R.layout.loading,null); View loaded = View.inflate(this,R.layout.loaded,null); View empty = View.inflate(this,R.layout.empty,null); mRecyclerView = (RecyclerView) findViewById(R.id.recycler); mRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh); BasicParams p = new BasicController.Builder() .layoutRes(R.layout.item) .header(header) .header(header2) .footer(footer) .empty(empty) .loaded(loaded) .loading(loading) .onLoadMore(new OnLoadMoreListener() { @Override public void onLoad() { mHandler.postDelayed(new Runnable() { @Override public void run() { if(loadCount <2){ mManList.addAll(random(mManList.size(),10)); mAdapter.notifyDataSetChanged(); mAdapter.finishLoad(); loadCount++; }else{ mManList.addAll(random(mManList.size(),10)); mAdapter.doneLoad(); } } },2000); } }) .build(); mManList.addAll(random(0,10)); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setAdapter(mAdapter = new MyAdapter(p,mManList)); mRecyclerView.addOnItemTouchListener(new OnRecyclerItemClickListener(mRecyclerView){ @Override public void onItemClick(ViewHolder vh) { int position = vh.getAdapterPosition(); Toast.makeText(getApplicationContext(), "position "+position + " clicked", Toast.LENGTH_SHORT).show(); Log.i("halcyon","position " +position + " click"); } }); mRefreshLayout.setOnRefreshListener(this); /*mRefreshLayout.post(new Runnable() { @Override public void run() { mRefreshLayout.setRefreshing(true); onRefresh(); } });*/ }
Example 20
Source File: RecyclerViewAdapterConverter.java From UniversalAdapter with Apache License 2.0 | 3 votes |
/** * Binds this adapter to the given {@link RecyclerView}, setting it as its adapter. This should be done by * construction or immediately after, before this adapter is used. This mechanism sets this class as the view's * adapter and permits certain functionality such as click events. Without it, this class will still function as * a normal {@link android.support.v7.widget.RecyclerView.Adapter}, but additional functionality may not work. * Ignore this step at your own risk. * * @param recyclerView The {@link RecyclerView} to bind to. */ public void bindToRecyclerView(RecyclerView recyclerView) { if (recyclerView != null) { recyclerView.setAdapter(this); recyclerView.addOnItemTouchListener(internalOnItemTouchListener); } }