ExpandableRecyclerview Inside a Cardview Recyclerview - android

I am totally familiar with ExpandableRecyclerview Or ExpandableLayout But I have a design that is a little bit unique and I am seeking help to achieve this implementation.
I Am Attaching the design
When the user clicks the arrow shown in the image the CardView Recyclerview should expand or inflate a recyclerview in between comment button and response section. How to do that. I have tried the ExpandableRecyclerview from ThoughtBot and ExpandableListView all this components add a child to parent.
I am using ExpandableRecyclerview from Thoughtbot,
com.thoughtbot.expandablerecyclerview
My Adapter Looks like as below.
public class ReviewRecyclerAdapter extends ExpandableRecyclerViewAdapter<ReviewViewHolder, CommentsViewHolder> {
private Context context;
public ReviewRecyclerAdapter(Context context,List<? extends ExpandableGroup> groups) {
super(groups);
this.context = context;
}
#Override
public ReviewViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item_review, parent, false);
return new ReviewViewHolder(view);
}
#Override
public CommentsViewHolder onCreateChildViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item_comments, parent, false);
return new CommentsViewHolder(view);
}
#Override
public void onBindChildViewHolder(CommentsViewHolder holder, int flatPosition, ExpandableGroup group, int childIndex) {
final CommentsModel comments = ((ReviewsModel) group).getItems().get(childIndex);
holder.setSubTitletName(comments.getComment());
}
#Override
public void onBindGroupViewHolder(ReviewViewHolder holder, int flatPosition, ExpandableGroup group) {
holder.setGenreTitle(context, group);
}
}
// View Holders
public class ReviewViewHolder extends GroupViewHolder {
private TextView titleName;
private ImageView arrow;
private ImageView icon;
public ReviewViewHolder(View itemView) {
super(itemView);
titleName = (TextView) itemView.findViewById(R.id.list_item_genre_name);
arrow = (ImageView) itemView.findViewById(R.id.list_item_genre_arrow);
}
public void setGenreTitle(Context context, ExpandableGroup title) {
if (title instanceof ReviewsModel) {
titleName.setText(title.getTitle());
if (((ReviewsModel) title).getReview()!= null && !((ReviewsModel) title).getReview().isEmpty()){
}
}
}
#Override
public void expand() {
animateExpand();
}
#Override
public void collapse() {
animateCollapse();
}
private void animateExpand() {
RotateAnimation rotate =
new RotateAnimation(360, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(300);
rotate.setFillAfter(true);
arrow.setAnimation(rotate);
}
private void animateCollapse() {
RotateAnimation rotate =
new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(300);
rotate.setFillAfter(true);
arrow.setAnimation(rotate);
}
}
public class CommentsViewHolder extends ChildViewHolder {
private TextView subTitleTextView;
public CommentsViewHolder(View itemView) {
super(itemView);
subTitleTextView = (TextView) itemView.findViewById(R.id.subtitle);
}
public void setSubTitletName(String name) {
subTitleTextView.setText(name);
}
}
//Review Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="24dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/review_details"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/list_avatar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:src="#drawable/profile_placeholder" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="16dp"
android:layout_toEndOf="#+id/list_avatar">
<TextView
android:id="#+id/list_item_genre_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:maxEms="15"
android:text=" Guru natha"
android:textStyle="bold"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxEms="15"
android:text=" From Mg Road"
android:layout_alignStart="#+id/list_item_genre_name"
android:layout_marginStart="10dp"
android:layout_below="#+id/list_item_genre_name" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true">
<TextView
android:id="#+id/days"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="10dp"
android:maxEms="15"
android:text=" 3 Days ago"
android:textSize="8sp"
android:textStyle="bold" />
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/days"
android:layout_below="#+id/days"
android:maxEms="15"
android:text=" 448 Views"
android:textSize="8sp" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/review_details"
android:layout_margin="20dp">
<TextView
android:id="#+id/review"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="10dp"
android:maxEms="15"
android:text="Review"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="10dp"
android:maxEms="15"
android:text="Rating"
android:textStyle="bold" />
<View
android:id="#+id/lineytf"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/review"
android:background="#color/black" />
<TextView
android:layout_marginTop="10dp"
android:id="#+id/review_conetent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/lineytf"
android:layout_below="#+id/lineytf"
android:maxLines="3"
android:maxEms="15"
android:text="#string/lorem_ipsum" />
</RelativeLayout>
<RelativeLayout
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/content">
<TextView
android:id="#+id/response"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:maxEms="15"
android:text="Response (2)"
android:textStyle="bold" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="10dp"
android:maxEms="15"
android:layout_above="#+id/line2"
android:src="#drawable/white_r_arrow"
android:text="arrow"
android:textStyle="bold"
android:id="#+id/list_item_genre_arrow" />
<View
android:id="#+id/line2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/response"
android:background="#color/black" />
<!--Add expandable views-->
<Button
android:id="#+id/commentsbutton"
android:textSize="12sp"
android:textAllCaps="false"
android:text="Comments"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_below="#+id/line2"
android:layout_toStartOf="#+id/button2" />
<Button
android:textSize="12sp"
android:textAllCaps="false"
android:text="56"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_below="#+id/list_item_genre_arrow"
android:layout_alignParentEnd="true"
android:id="#+id/button2" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
//Comment Layout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="40dp">
<ImageView
android:id="#+id/list_item_genre_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginLeft="70dp"
android:layout_alignParentRight="true"
android:src="#drawable/android" />
<TextView
android:id="#+id/subtitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="100dp"
android:gravity="center_vertical"
tools:text="SubTitle" />
</FrameLayout>
Current Screenshot :
Please do shoot the closest solution if you have.

Related

Piccaso Image not Loading

My Image is Not loading ,when i was using Picaaso and Glide, And its give URL Path, when i was running the app. I also Attached the pHoto of Image which having error. I tried Everything,Even i used Glide library also.But Image was not loading and its give the app error.ALso there is no error in LOGCAT.Please help , i m new in this.
App Image Error
Master Fragment
public void initData(String authorization) {
ApiInterface apiInterface =
ApiClient.getClient().create(ApiInterface.class);
Call<List<MasterEventResponse>> call =
apiInterface.getAllDetail("Token "
+ authorization);
call.enqueue(new Callback<List<MasterEventResponse>>() {
#Override
public void onResponse(Call<List<MasterEventResponse>> call,
Response<List<MasterEventResponse>> response) {
Log.d(" MasterResponse", response.toString());
if (response.isSuccessful()) {
List<MasterEventResponse> masterResponse = response.body();
MasterEventResponse mMasterEventResponse;
for (int i = 0; i < masterResponse.size(); i++) {
String time = masterResponse.get(i).getStartTime();
Integer duration =
masterResponse.get(i).getEventDuration();
String topic = masterResponse.get(i).getTopic();
String name = masterResponse.get(i).getMasterName();
String image = masterResponse.get(i).getEventImage();
Integer id = masterResponse.get(i).getId();
mMasterEventResponse = new MasterEventResponse(id,
time, duration, topic, name, image);
masterEventResponse.add(mMasterEventResponse);
masterAdapter.notifyDataSetChanged();
} else {
Toast.makeText(context, "Something is crash.",
Toast.LENGTH_SHORT).show();
}
}
}
}
MasterAdapter
public class MasterAdapter extends
RecyclerView.Adapter<MasterAdapter.ViewHolder> {
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.mTime.setText(masterEventResponse.get(position).getStartTime());
holder.mDuration.setText(Integer.toString(masterEventResponse.get(position).getEventDuration()));
holder.mDescription.setText(masterEventResponse.get(position).getTopic());
holder.mMentor.setText(masterEventResponse.get(position).getMasterName());
String url = masterEventResponse.get(position).getEventImage();
Picasso.get()
.load(url)
.resize(50, 50)
.placeholder(R.drawable.image)
.into(holder.mImage);
#Override
public int getItemCount() {
return masterEventResponse.size();
//return ();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView mTime;
public TextView mDuration;
public TextView mDescription;
public TextView mMentor;
public ImageView mImage;
// public LinearLayout mStatus;
public ViewHolder(#NotNull View itemView) {
super(itemView);
mTime = itemView.findViewById(R.id.tv_time);
mDuration= itemView.findViewById(R.id.tv_duration);
mDescription = itemView.findViewById(R.id.tv_detail);
mMentor = itemView.findViewById(R.id.tv_mentorName);
mImage = itemView.findViewById(R.id.img_master);
}
}
}
MOdel Class
Integer id, String masterName, Integer eventDuration,
String topic, String eventImage, String startTime) {
}
XML File
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Theme.Design.NoActionBar"
android:orientation="horizontal">
<androidx.cardview.widget.CardView
android:id="#+id/cv_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:background="#BACCD1"
app:cardCornerRadius="10dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="120dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:background="#BACCD1"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
app:cardCornerRadius="5dp"
app:cardElevation="2dp">
<ImageView
android:id="#+id/img_master"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/decor"/>
</androidx.cardview.widget.CardView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:background="#BACCD1"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp">
<TextView
android:id="#+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10:45AM"
android:layout_marginRight="50dp"
android:textSize="18sp"
android:textColor="#android:color/black"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Train your mind and get richer.."
android:textStyle="bold"
android:textColor="#color/black"
android:textSize="12sp"
android:layout_marginLeft="5sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_mentorName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sadhna Gupta"
android:layout_marginTop="35dp"
android:textColor="#color/black"
android:textSize="12sp"
android:layout_marginLeft="5sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:gravity="center_vertical">
<LinearLayout
android:id="#+id/ll_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_corps"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/ic_corporate"
/>
<TextView
android:id="#+id/tv_corps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Corporate"
android:textColor="#color/black"
android:textSize="12sp"
android:layout_marginLeft="5sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/lnl_restaurant"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:orientation="horizontal"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:gravity="center"
android:background="#drawable/ic_join">
<TextView
android:id="#+id/tv_join"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Join"
android:textColor="#845247"
android:textSize="12sp"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/lnl_favorite"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:layout_alignParentRight="true">
<TextView
android:id="#+id/tv_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="40 min"
android:layout_alignParentTop="true"/>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>

Recycler view setLayoutManager Android Studio [duplicate]

This question already has answers here:
android.content.res.Resources$NotFoundException: String resource ID #0x0
(8 answers)
Closed 3 years ago.
RecyclerView isn't showed without setLayoutManager, but setLayoutManager makes my program crash. This method was demonstrated in all of the tutorials I have watched. Yeah, I know, there is too much code with a lot of garbage, but the error can be anywhere, so I hope you can help me(
StoreInfoPage.java (get it just like the MainActivity)
public class StoreInfoPage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.store_info_page);
RecyclerView lastMonthSellsList = findViewById(R.id.last_month_sells_list);
ArrayList<Product> products = new ArrayList<>();
products.add(new Product(4, 5, true, true, 16000, 12000));
products.add(new Product(4, 5, true, true, 16000, 12000));
StoreSellingAdapter adapter = new StoreSellingAdapter(this, products);
lastMonthSellsList.setAdapter(adapter);
lastMonthSellsList.setLayoutManager(new LinearLayoutManager(this));
}
}
store_info_page.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".StoreInfoPage">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView41"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="bottom"
android:textAllCaps="false"
android:textSize="18sp"
android:textStyle="bold|italic" />
<ImageButton
android:id="#+id/imageButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#android:color/transparent"
android:scaleType="fitEnd"
app:srcCompat="#android:drawable/ic_menu_info_details" />
</LinearLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"
android:layout_marginBottom="10dp"/>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_slab_bold"
android:text="Кофе 3в1"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold|italic" />
<EditText
android:id="#+id/editText5"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:ems="10"
android:fontFamily="#font/roboto_slab_bold"
android:inputType="number"
android:textAlignment="center" />
<TextView
android:id="#+id/textView17"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/roboto_slab_bold"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_slab_bold"
android:text="Чёрное Кофе"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold|italic" />
<EditText
android:id="#+id/editText6"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:ems="10"
android:fontFamily="#font/roboto_slab_bold"
android:inputType="number"
android:textAlignment="center" />
<TextView
android:id="#+id/textView18"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/roboto_slab_bold"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_slab_bold" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_slab_bold"
android:textColor="#000000" />
<TextView
android:id="#+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_slab_bold"
android:textColor="#000000" />
</TableRow>
</TableLayout>
<Switch
android:id="#+id/switch1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:showText="true"
android:text="ДОЛГ"
android:textAlignment="center"
android:textSize="24sp" />
<Button
android:id="#+id/button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_slab_bold"
android:text="Добавить"
android:textSize="24sp" />
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<TextView
android:id="#+id/textView20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_slab_bold"
android:text="ПРОШЛЫЙ МЕСЯЦ"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="30sp" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/last_month_sells_list"
/>
</LinearLayout>
store_sell_list_table_row.xml (Adapter xml for RecyclerView)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:id="#+id/sells_list_adapter_layout"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/whiteCoffeeAdapter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_slab_bold"
android:text="Кофе 3в1"
android:textColor="#000000"
android:textSize="24sp" />
<TextView
android:id="#+id/whiteCoffeeQuantityAdapter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/roboto_slab_bold"
android:text="0"
android:textColor="#000000" />
<TextView
android:id="#+id/whiteCoffeePriceAdapter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/roboto_slab_bold"
android:text="0"
android:textColor="#000000" />
<TextView
android:id="#+id/whiteCoffeeTotalPriceAdapter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/roboto_slab_bold"
android:text="0"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/blackCoffeeAdapter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_slab_bold"
android:text="Чёрное Кофе"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/blackCoffeeQuantityAdapter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/roboto_slab_bold"
android:text="0"
android:textColor="#000000" />
<TextView
android:id="#+id/blackCoffeePriceAdapter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/roboto_slab_bold"
android:text="0"
android:textColor="#000000" />
<TextView
android:id="#+id/blackCoffeeTotalPriceAdapter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/roboto_slab_bold"
android:text="0"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_slab_bold"
android:textColor="#000000" />
<TextView
android:id="#+id/textView39"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/roboto_slab_bold"
android:textColor="#000000" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/coffeeTotalPriceAdapter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/roboto_slab_bold"
android:text="0"
android:textColor="#000000" />
</TableRow>
</TableLayout>
<TextView
android:id="#+id/status_text_view_adapter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ОПЛАЧЕНО"
android:textAlignment="center"
android:textStyle="bold" />
</LinearLayout>
StoreSellingAdapter (Adapter class)
public class StoreSellingAdapter extends RecyclerView.Adapter<StoreSellingAdapter.ViewHolder>{
private ArrayList<Product> products;
private Context context;
StoreSellingAdapter(Context context, ArrayList<Product> products) {
this.products = products;
this.context = context;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.store_sell_list_table_row, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
Product product = products.get(position);
holder.whiteCoffeeQuantity.setText(product.getWhiteCoffeeQuantity());
holder.blackCoffeeQuantity.setText(product.getBlackCoffeeQuantity());
holder.whiteCoffeePrice.setText(product.getWhiteCoffeePrice());
holder.blackCoffeePrice.setText(product.getBlackCoffeePrice());
holder.whiteCoffeeTotalPrice.setText(product.getWhiteCoffeeTotalPrice());
holder.blackCoffeeTotalPrice.setText(product.getBlackCoffeeTotalPrice());
holder.coffeeTotalPrice.setText(product.getCoffeeTotalPrice());
if(product.isDebt() && product.isPaid()) {
holder.statusTextViewAdapter.setText("ДОЛГ(ОПЛАЧЕНО)");
holder.parentLayout.setBackgroundColor(Color.parseColor("#ef5350"));
}
}
#Override
public int getItemCount() {
return products.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
TextView whiteCoffeeQuantity;
TextView blackCoffeeQuantity;
TextView whiteCoffeePrice;
TextView blackCoffeePrice;
TextView whiteCoffeeTotalPrice;
TextView blackCoffeeTotalPrice;
TextView coffeeTotalPrice;
TextView statusTextViewAdapter;
LinearLayout parentLayout;
ViewHolder(#NonNull View itemView) {
super(itemView);
whiteCoffeeQuantity = itemView.findViewById(R.id.whiteCoffeeQuantityAdapter);
blackCoffeeQuantity = itemView.findViewById(R.id.blackCoffeeQuantityAdapter);
whiteCoffeePrice = itemView.findViewById(R.id.whiteCoffeePriceAdapter);
blackCoffeePrice = itemView.findViewById(R.id.blackCoffeePriceAdapter);
whiteCoffeeTotalPrice = itemView.findViewById(R.id.whiteCoffeeTotalPriceAdapter);
blackCoffeeTotalPrice = itemView.findViewById(R.id.blackCoffeeTotalPriceAdapter);
coffeeTotalPrice = itemView.findViewById(R.id.coffeeTotalPriceAdapter);
parentLayout = itemView.findViewById(R.id.sells_list_adapter_layout);
statusTextViewAdapter = itemView.findViewById(R.id.status_text_view_adapter);
}
}
}
Product.java
public class Product {
private int whiteCoffeeQuantity;
private int blackCoffeeQuantity;
private boolean isDebt;
private boolean isPaid;
private int whiteCoffeePrice;
private int blackCoffeePrice;
private int whiteCoffeeTotalPrice;
private int blackCoffeeTotalPrice;
private int coffeeTotalPrice;
public Product(int whiteCoffeeQuantity, int blackCoffeeQuantity, boolean isDebt, boolean isPaid, int whiteCoffeePrice, int blackCoffeePrice) {
this.whiteCoffeeQuantity = whiteCoffeeQuantity;
this.blackCoffeeQuantity = blackCoffeeQuantity;
this.isDebt = isDebt;
this.isPaid = isPaid;
this.whiteCoffeePrice = whiteCoffeePrice;
this.blackCoffeePrice = blackCoffeePrice;
whiteCoffeeTotalPrice = whiteCoffeeQuantity*whiteCoffeePrice;
blackCoffeeTotalPrice = blackCoffeeQuantity*blackCoffeePrice;
coffeeTotalPrice = whiteCoffeeTotalPrice+blackCoffeeTotalPrice;
}
public int getWhiteCoffeeQuantity() {
return whiteCoffeeQuantity;
}
public void setWhiteCoffeeQuantity(int whiteCoffeeQuantity) {
this.whiteCoffeeQuantity = whiteCoffeeQuantity;
}
public int getBlackCoffeeQuantity() {
return blackCoffeeQuantity;
}
public void setBlackCoffeeQuantity(int blackCoffeeQuantity) {
this.blackCoffeeQuantity = blackCoffeeQuantity;
}
public boolean isDebt() {
return isDebt;
}
public void setDebt(boolean debt) {
isDebt = debt;
}
public boolean isPaid() {
return isPaid;
}
public void setPaid(boolean paid) {
isPaid = paid;
}
public int getWhiteCoffeePrice() {
return whiteCoffeePrice;
}
public void setWhiteCoffeePrice(int whiteCoffeePrice) {
this.whiteCoffeePrice = whiteCoffeePrice;
}
public int getBlackCoffeePrice() {
return blackCoffeePrice;
}
public void setBlackCoffeePrice(int blackCoffeePrice) {
this.blackCoffeePrice = blackCoffeePrice;
}
public int getWhiteCoffeeTotalPrice() {
return whiteCoffeeTotalPrice;
}
public void setWhiteCoffeeTotalPrice(int whiteCoffeeTotalPrice) {
this.whiteCoffeeTotalPrice = whiteCoffeeTotalPrice;
}
public int getBlackCoffeeTotalPrice() {
return blackCoffeeTotalPrice;
}
public void setBlackCoffeeTotalPrice(int blackCoffeeTotalPrice) {
this.blackCoffeeTotalPrice = blackCoffeeTotalPrice;
}
public int getCoffeeTotalPrice() {
return coffeeTotalPrice;
}
public void setCoffeeTotalPrice(int coffeeTotalPrice) {
this.coffeeTotalPrice = coffeeTotalPrice;
}
}
I really don't know you!
Everything is because of TextView.setText(Int).
Just replace Int with String.valueOf(Int).

Increment the value of TextView of child of particular Parent

This is the getChildView inside the Adapter class...
public View getChildView(int parent, int child, boolean lastChild, View view, ViewGroup viewGroup) {
ArrayList<String> itemDetails= (ArrayList<String>)getChild(parent,child);
if(view==null)
{
LayoutInflater inflater= (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view= inflater.inflate(R.layout.child_layout,viewGroup,false);
}
TextView textView =(TextView)view.findViewById(R.id.textView2);
textView.setText(itemDetails.get(0));
TextView textView1(TextView)view.findViewById(R.id.itemdescription);
textView1.setText(itemDetails.get(1));
TextView textView3= (TextView)view.findViewById(R.id.price);
textView3.setText(itemDetails.get(2));
final TextView textView2 = (TextView)view.findViewById(R.id.counterTextView);
ImageButton add = (ImageButton)view.findViewById(R.id.imageButton);
final ImageButton remove = (ImageButton)view.findViewById(R.id.imageButton1);
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textView2.setText(String.valueOf(Integer.parseInt(textView2.getText().toString())+1));
remove.setVisibility(View.VISIBLE);
}
});
remove.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(Integer.parseInt(textView2.getText().toString())==0)
{
remove.setVisibility(View.INVISIBLE);
}
else {
textView2.setText(String.valueOf(Integer.parseInt(textView2.getText().toString()) - 1));
}
}
});
return view;
}
This is the ChildLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:background="#FFFFFF">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
app:srcCompat="#drawable/k_meals_rs"
android:id="#+id/imageView6" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textSize="20sp"
android:textColor="#000000"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingRight="10dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_remove_black"
android:id="#+id/imageButton1"
android:background="#drawable/round_button"
android:visibility="invisible"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textColor="#000000"
android:id="#+id/counterTextView" />
<ImageButton
app:srcCompat="#drawable/ic_add_black"
android:id="#+id/imageButton"
android:background="#drawable/round_button"
android:layout_width="29dp"
android:layout_height="29dp" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="10dp">
<TextView
android:id="#+id/itemdescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:maxEms="15"
android:textColor="#000000"/>
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="₹150"
android:textColor="#000000"/>
</RelativeLayout>
</LinearLayout>
i want to increment & decrements the value of counterTextView as the the + and - buttons are pressed.. but as i do so it increment and decrements the value of counterTextView in other child in other parents with same index value...any idea how to overcome this problem.. thnx

ListView Items changed automatically in Fragment android

when I scroll the listview the items changed automatically, in other word an item override other item's view like : when I click on favorite button other items has been changed like this
example:
the item that I clicked
I didn't click on this item
here is my code :
CustomListAdapter.java :
public class CustomListAdapter extends BaseAdapter {
private Context context;
LayoutInflater inflater;
boolean isVoter;
public CustomListAdapter(Context c ) {
this.context = c;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null){
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.date_view,null);
viewHolder = new ViewHolder();
viewHolder.vote = (ImageButton) convertView.findViewById(R.id.vote);
}else {
viewHolder = (ViewHolder)convertView.getTag();
}
isVoter = newsItemArray.get(position).isVoter();
viewHolder.vote.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (!Utility.isNetworkAvailable(context))
Toast.makeText(context, R.string.no_network, Toast.LENGTH_LONG).show();
else
voteBtn( position);
}});
return convertView;
}
public void voteBtn(int position){
if ( !isVoter ) {
viewHolder.vote.setImageResource(R.drawable.button_pressed);
}
else{
viewHolder.vote.setImageResource(R.drawable.button_normal);
}
isVoter = !isVoter;
}
}
private class ViewHolder{
ImageButton vote ;
}
#Override
public int getCount() {
return newsItemArray.size();
}
#Override
public Object getItem(int position) {
return newsItemArray.get(position).getTitle();
}
#Override
public long getItemId(int position) {
return position;
}
}
date_view.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#f2f2f2"
android:gravity="center"
android:elevation="8dp"
android:layout_margin="10dp">
<android.support.v7.widget.CardView
android:id="#+id/newsCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#fff"
android:layout_margin="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/newsimage1"
android:layout_width="45px"
android:layout_height="45px"
android:src="#mipmap/ic_launcher"
android:scaleType="centerCrop"
/>
<TextView
android:id="#+id/newsname"
android:layout_marginLeft="16dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fox News."
android:textColor="#000000"
android:textSize="20dp"
android:layout_gravity="center"
/>
<TextView
android:id="#+id/time"
android:layout_weight="0.6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2 day ago"
android:textColor="#color/listsub1"
android:textSize="14dp"
android:layout_gravity="center"
/>
<ImageView
android:id="#+id/more"
android:visibility="invisible"
android:layout_width="15dp"
android:layout_height="22dp"
android:src="#drawable/more"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="12dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/sourceNews"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="5dp"
>
<TextView
android:id="#+id/news"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Trump’s Plan for AmericanMade iPhonew Wold Be Disastrous. Trump’s Plan for AmericanMade iPhonew Wold Be Disastrous"
android:textSize="20dp"
android:textColor="#color/listtext"
android:lineSpacingExtra="3dp"
/>
<TextView
android:id="#+id/newssub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Why even a President Trump couldn’t make Apple manufacture iPhone in the state."
android:layout_marginTop="5dp"
android:textSize="13dp"
android:textColor="#color/listsub1"
android:lineSpacingExtra="3dp"
/>
<TextView
android:id="#+id/votes_num"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10dp"
android:textStyle="bold"
android:textColor="#f40000"
android:maxLines="1"
android:layout_marginTop="5dp"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<ImageButton
android:id="#+id/vote"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/star"
android:background="#00ffffff"
android:paddingLeft="5dp" />
<!--
<ImageButton
android:id="#+id/vote"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="#drawable/star"
android:paddingLeft="5dp" />
<Button
android:id="#+id/share"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Share"
android:textColor="#color/background_material_light"/>
<Button
android:id="#+id/comment"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Comment"
android:textColor="#color/background_material_light"/>
-->
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
isVoter and viewHolder should not be global variables within the Adapter. Meaning, you are not actually changing whatever member is returned by newsItemArray.get(position).isVoter()
Try adding the position to the ViewHolder object. Then pass the ViewHolder object into the constructor of the viewHolder.vote.setOnClickListener. Within the OnClickListener you can then call
isVoter = newsItemArray.get(viewHolder.position).isVoter();
newsItemArray.get(viewHolder.position).setVoter(!isVoter);

How to get Item Clicked in Fragment's Recycler View to activity?

i have an activity which is having about 4 fragment and fragment have a recyclerview and in each recyclerview item there is a button.. i have a textfield in activity and i want to show the no. of button clicked.
thats my activity.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="3"
tools:context="com.example.khaalijeb.newlistview_module.PromoCodeActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.4"
android:background="#f9f9f9"
android:elevation="5dp">
<ImageView
android:id="#+id/back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:src="#drawable/greyback" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/back"
android:text="Fancy Some Deals ?"
android:textSize="16dp"
android:textStyle="bold" />
<Button
android:id="#+id/skip"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/roundedcorneredittext"
android:text="SKIP"
android:textColor="#0277bd"
android:textSize="12dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.55"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabIndicatorColor="#E12728"
app:tabMode="scrollable"
app:tabSelectedTextColor="#E12728"
app:tabTextAppearance="#style/TextAppearance.Design.Tab" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.05"
android:background="#f9f9f9"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.2"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#727272"
/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel">
<EditText
android:id="#+id/spass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:hint="Promo Code"
android:inputType="textPassword"
android:paddingLeft="10dp"
android:textColor="#color/material_blue_grey_800"
android:textSize="14dp" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#727272" />
<Button
android:id="#+id/apply"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:background="#drawable/roundedcorneredittext"
android:text="APPLY"
android:textColor="#0277bd"
android:textSize="12dp" />
<Button
android:id="#+id/applied"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:background="#drawable/roundedcorneredittext"
android:text="APPLIED"
android:textColor="#0277bd"
android:textSize="12dp"
android:visibility="invisible"
/>
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.8">
<TextView
android:id="#+id/credittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textSize="12dp"
android:text="Credited To Jeb No." />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/credittext"
android:layout_toRightOf="#+id/credittext"
android:text="C100"
android:textSize="12dp"
/>
<TextView
android:id="#+id/amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/credittext"
android:layout_marginRight="16dp"
android:text="Rs.100"
android:textSize="12dp"
/>
<TextView
android:id="#+id/pickdeal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/credittext"
android:layout_margin="5dp"
android:text="Haven't Picked Any Deals Yet"
android:textColor="#78909C"
android:textSize="12dp" />
<TextView
android:id="#+id/dealamount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/amount"
android:text="Rs.50"
android:layout_marginRight="16dp"
android:layout_alignTop="#+id/pickdeal"
android:textSize="12dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/dealamount"
android:text="+"
android:layout_alignTop="#+id/dealamount"
android:layout_marginRight="2dp"
android:textSize="12dp"
/>
<TextView
android:id="#+id/discount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/pickdeal"
android:text="Discount"
android:layout_alignLeft="#+id/pickdeal"
android:textColor="#F44336"
android:textSize="12dp"
android:layout_marginTop="5dp"
/>
<TextView
android:id="#+id/discountedamount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Rs.50"
android:textColor="#F44336"
android:layout_alignTop="#+id/discount"
android:layout_marginRight="16dp"
android:textSize="12dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/discountedamount"
android:layout_alignTop="#+id/discountedamount"
android:text="-"
android:textColor="#F44336"
android:layout_marginRight="2dp"
/>
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.5">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0277bd"
android:text="PROCEED TO PAY" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
recyelrview item
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/llContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
card_view:cardBackgroundColor="#f9f9f9"
card_view:cardCornerRadius="1dp"
card_view:cardElevation="5dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:orientation="vertical"
android:weightSum="2"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.7">
<ImageView
android:id="#+id/icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:src="#drawable/nike" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:orientation="horizontal"
android:weightSum="2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5">
<TextView
android:id="#+id/brandname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="hello"
android:textAllCaps="true"
android:textColor="#000000"
android:textSize="14dp"
android:typeface="sans" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/brandname"
android:layout_below="#+id/brandname"
android:layout_marginTop="10dp"
android:text="Get 50% off on Apparels"
android:textSize="12dp" />
<TextView
android:id="#+id/seemore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/brandname"
android:layout_below="#+id/title"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="See More"
android:textSize="12dp" />
<ImageView
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignTop="#+id/seemore"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/seemore"
android:src="#drawable/sendgrey" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.5">
<Button
android:id="#+id/free"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_centerInParent="true"
android:layout_marginBottom="16dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="16dp"
android:background="#drawable/roundedcorneredittext"
android:text="Free"
android:textColor="#0277bd"
android:textSize="12dp"
/>
<Button
android:id="#+id/taken"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_centerInParent="true"
android:layout_marginBottom="16dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="16dp"
android:background="#drawable/roundedcorner1"
android:text="Great!"
android:textColor="#ffffff"
android:textSize="12dp"
android:visibility="invisible"
/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Adapter.java
public class PromoCodeRecyclerViewAdapter extends RecyclerView.Adapter<PromoCodeRecyclerViewAdapter.MyViewholder> {
private ClickListener clickListener;
private LayoutInflater inflator;
private Context mcontext;
Typeface font;
public Button b1;
public ImageButton b2;
List<promocodedata> data = Collections.emptyList();
public PromoCodeRecyclerViewAdapter(Context context, List<promocodedata> y, Typeface font) {
inflator = LayoutInflater.from(context);
this.data = y;
this.mcontext = context;
this.font = font;
}
public void setClickListener(ClickListener clickListener) {
this.clickListener = clickListener;
}
#Override
public MyViewholder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflator.inflate(R.layout.promocode_item_layout, parent, false);
MyViewholder holder = new MyViewholder(view);
return holder;
}
#Override
public void onBindViewHolder(final MyViewholder holder, int position) {
promocodedata current = data.get(position);
holder.brandicon.setImageResource(current.brandicon);
holder.brandname.setText(current.brandname);
holder.title.setText(current.title);
holder.free.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
holder.taken.setVisibility(View.VISIBLE);
holder.free.setVisibility(View.INVISIBLE);
}
});
holder.taken.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
holder.taken.setVisibility(View.INVISIBLE);
holder.free.setVisibility(View.VISIBLE);
}
});
}
#Override
public int getItemCount() {
return data.size();
}
public interface ClickListener {
void itemClicked(View v, int position);
}
class MyViewholder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView brandicon;
TextView brandname;
TextView title;
Button free;
Button taken;
public MyViewholder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
brandicon = (ImageView) itemView.findViewById(R.id.icon);
brandname = (TextView) itemView.findViewById(R.id.brandname);
title = (TextView) itemView.findViewById(R.id.title);
free = (Button)itemView.findViewById(R.id.free);
taken = (Button)itemView.findViewById(R.id.taken);
}
#Override
public void onClick(View v) {
if (clickListener != null) {
clickListener.itemClicked(v, getPosition());
}
}
}
}
You need to create your onitemclick because RecyclerView does not have a OnItemClick like Listview, i have an example in Github check it.

Categories

Resources