Support
Quality
Security
License
Reuse
kandi has reviewed ViewPagerCards and discovered the below as its top functions. This is intended to give you an instant insight into ViewPagerCards implemented functionality, and help decide if they suit your requirements.
Showcasing premium features
An app intro
A small gallery of images
License
Copyright 2016 Rúben Sousa
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
How to get view and scroll like make my trip application "Hot Deals" section.?
cardviewPager .addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
imagePager.setCurrentItem(position);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
ViewPager cards inspired by Duolingo
android:id="@+id/card_button"
Button theButton = (Button) view.findViewById(R.id.card_button);
theButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//The Action Here
}
});
-----------------------
android:id="@+id/card_button"
Button theButton = (Button) view.findViewById(R.id.card_button);
theButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//The Action Here
}
});
-----------------------
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardUseCompatPadding="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="24dp">
<TextView
android:id="@+id/titleTextView"
style="@style/TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/contentTextView"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"/>
<Button
android:id="@+id/btn_click"
style="@style/ButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Button" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="-5dp"
android:src="@drawable/ic_bookmark_24dp" />
</FrameLayout>
</android.support.v7.widget.CardView>
public class CardPagerAdapter extends PagerAdapter implements CardAdapter {
Button btn_click;
private List<CardView> mViews;
private List<CardItem> mData;
private float mBaseElevation;
Context mContext;
public CardPagerAdapter(MainActivity mainActivity) {
mData = new ArrayList<>();
mViews = new ArrayList<>();
mContext = mainActivity;
}
public void addCardItem(CardItem item) {
mViews.add(null);
mData.add(item);
}
public float getBaseElevation() {
return mBaseElevation;
}
@Override
public CardView getCardViewAt(int position) {
return mViews.get(position);
}
@Override
public int getCount() {
return mData.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, final int position) {
View view = LayoutInflater.from(container.getContext())
.inflate(R.layout.adapter, container, false);
container.addView(view);
bind(mData.get(position), view);
CardView cardView = (CardView) view.findViewById(R.id.cardView);
if (mBaseElevation == 0) {
mBaseElevation = cardView.getCardElevation();
}
cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
mViews.set(position, cardView);
btn_click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext, "List Position " + position, Toast.LENGTH_SHORT).show();
}
});
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
mViews.set(position, null);
}
private void bind(CardItem item, View view) {
TextView titleTextView = (TextView) view.findViewById(R.id.titleTextView);
TextView contentTextView = (TextView) view.findViewById(R.id.contentTextView);
btn_click = (Button) view.findViewById(R.id.btn_click);
titleTextView.setText(item.getTitle());
contentTextView.setText(item.getText());
}
}
mCardAdapter = new CardPagerAdapter(MainActivity.this);
-----------------------
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardUseCompatPadding="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="24dp">
<TextView
android:id="@+id/titleTextView"
style="@style/TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/contentTextView"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"/>
<Button
android:id="@+id/btn_click"
style="@style/ButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Button" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="-5dp"
android:src="@drawable/ic_bookmark_24dp" />
</FrameLayout>
</android.support.v7.widget.CardView>
public class CardPagerAdapter extends PagerAdapter implements CardAdapter {
Button btn_click;
private List<CardView> mViews;
private List<CardItem> mData;
private float mBaseElevation;
Context mContext;
public CardPagerAdapter(MainActivity mainActivity) {
mData = new ArrayList<>();
mViews = new ArrayList<>();
mContext = mainActivity;
}
public void addCardItem(CardItem item) {
mViews.add(null);
mData.add(item);
}
public float getBaseElevation() {
return mBaseElevation;
}
@Override
public CardView getCardViewAt(int position) {
return mViews.get(position);
}
@Override
public int getCount() {
return mData.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, final int position) {
View view = LayoutInflater.from(container.getContext())
.inflate(R.layout.adapter, container, false);
container.addView(view);
bind(mData.get(position), view);
CardView cardView = (CardView) view.findViewById(R.id.cardView);
if (mBaseElevation == 0) {
mBaseElevation = cardView.getCardElevation();
}
cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
mViews.set(position, cardView);
btn_click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext, "List Position " + position, Toast.LENGTH_SHORT).show();
}
});
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
mViews.set(position, null);
}
private void bind(CardItem item, View view) {
TextView titleTextView = (TextView) view.findViewById(R.id.titleTextView);
TextView contentTextView = (TextView) view.findViewById(R.id.contentTextView);
btn_click = (Button) view.findViewById(R.id.btn_click);
titleTextView.setText(item.getTitle());
contentTextView.setText(item.getText());
}
}
mCardAdapter = new CardPagerAdapter(MainActivity.this);
-----------------------
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardUseCompatPadding="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="24dp">
<TextView
android:id="@+id/titleTextView"
style="@style/TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/contentTextView"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"/>
<Button
android:id="@+id/btn_click"
style="@style/ButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Button" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="-5dp"
android:src="@drawable/ic_bookmark_24dp" />
</FrameLayout>
</android.support.v7.widget.CardView>
public class CardPagerAdapter extends PagerAdapter implements CardAdapter {
Button btn_click;
private List<CardView> mViews;
private List<CardItem> mData;
private float mBaseElevation;
Context mContext;
public CardPagerAdapter(MainActivity mainActivity) {
mData = new ArrayList<>();
mViews = new ArrayList<>();
mContext = mainActivity;
}
public void addCardItem(CardItem item) {
mViews.add(null);
mData.add(item);
}
public float getBaseElevation() {
return mBaseElevation;
}
@Override
public CardView getCardViewAt(int position) {
return mViews.get(position);
}
@Override
public int getCount() {
return mData.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, final int position) {
View view = LayoutInflater.from(container.getContext())
.inflate(R.layout.adapter, container, false);
container.addView(view);
bind(mData.get(position), view);
CardView cardView = (CardView) view.findViewById(R.id.cardView);
if (mBaseElevation == 0) {
mBaseElevation = cardView.getCardElevation();
}
cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
mViews.set(position, cardView);
btn_click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext, "List Position " + position, Toast.LENGTH_SHORT).show();
}
});
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
mViews.set(position, null);
}
private void bind(CardItem item, View view) {
TextView titleTextView = (TextView) view.findViewById(R.id.titleTextView);
TextView contentTextView = (TextView) view.findViewById(R.id.contentTextView);
btn_click = (Button) view.findViewById(R.id.btn_click);
titleTextView.setText(item.getTitle());
contentTextView.setText(item.getText());
}
}
mCardAdapter = new CardPagerAdapter(MainActivity.this);
how to set different onclick listener for each button populated by a recyclerview
Switch(position){
case 0:
//Button No.1
break;
case 1:
//Button No.2
break;
.....
}
-----------------------
public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.ViewHolder> {
Context context;
List<Category> list;
public CategoryAdapter(Context context, List<Category> list){
this.list = list;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.item_category, null);
return new CategoryAdapter.ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
viewHolder.btnOne.setOnItemClickListener(new View.OnItemClickListener{
// do something
});
}
@Override
public int getItemCount() {
return list.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
Button btnOne, btnTwo;
public ViewHolder(View view) {
super(view);
btnOne = view.findViewById(R.id.btn_one);
btnTwo = view.findViewById(R.id.btn_two);
}
}
}
QUESTION
How to get view and scroll like make my trip application "Hot Deals" section.?
Asked 2018-Apr-23 at 13:54i followed this tutorial "https://github.com/DevExchanges/ViewPagerCards" i got the view like hotdeals section of MMT.But now i also want to change the image while swiping of cardview same as MMT.
ANSWER
Answered 2018-Apr-23 at 13:54cardviewPager .addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
imagePager.setCurrentItem(position);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit