From 3be7d85c8d89ade19e18c89d19e52b6bc732c635 Mon Sep 17 00:00:00 2001 From: IvanaE Date: Sun, 18 Nov 2018 13:40:28 -0500 Subject: [PATCH] waiting for dbhelper to finish recycler view --- .../olympusservices/FindServiceProvider.java | 72 +++++++++++++++++++ .../layout/activity_find_service_provider.xml | 5 ++ 2 files changed, 77 insertions(+) diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/FindServiceProvider.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/FindServiceProvider.java index 5bc311c..aadd2ca 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/FindServiceProvider.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/FindServiceProvider.java @@ -2,14 +2,20 @@ package com.uottawa.olympus.olympusservices; import android.app.DatePickerDialog; import android.app.TimePickerDialog; +import android.content.Context; import android.content.Intent; +import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.Button; import android.widget.DatePicker; import android.widget.RatingBar; +import android.widget.TextView; import android.widget.TimePicker; import android.widget.Toast; @@ -153,4 +159,70 @@ public class FindServiceProvider extends AppCompatActivity { } } } + + + public class MyAdapter extends RecyclerView.Adapter { + + private ServiceProvider[] serviceProviders; + private Context context; + + // Provide a reference to the views for each data item + // Complex data items may need more than one view per item, and + // you provide access to all the views for a data item in a view holder + + // Provide a suitable constructor (depends on the kind of dataset) + public MyAdapter(ServiceProvider[] serviceProviders, Context context) { + this.serviceProviders = serviceProviders; + } + + // Create new views (invoked by the layout manager) + @NonNull + @Override + public ProviderHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.service_list_item, parent, false); + ProviderHolder vh = new ProviderHolder(v); + return vh; + } + + // Replace the contents of a view (invoked by the layout manager) + @Override + public void onBindViewHolder(ProviderHolder holder, int position) { + ServiceProvider serviceprovider = serviceProviders[position]; + holder.name.setText(serviceprovider.getFirstname()+" "+serviceprovider.getLastname()); + holder.rate.setText(String.format("$%,.2f", serviceprovider.getRating())); + + + + } + + // Return the size of your dataset (invoked by the layout manager) + @Override + public int getItemCount() { + return serviceProviders.length; + } + + class ProviderHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ + + TextView name; + TextView rate; + + public ProviderHolder(View row){ + super(row); + name = row.findViewById(R.id.Name); + rate = row.findViewById(R.id.Rate); + row.setOnClickListener(this); + } + @Override + public void onClick(View view) { + TextView nameview = (TextView)view.findViewById(R.id.Name); + String name = nameview.getText().toString(); + + } + + + } + + + } } diff --git a/OlympusServices/app/src/main/res/layout/activity_find_service_provider.xml b/OlympusServices/app/src/main/res/layout/activity_find_service_provider.xml index 16bf843..c2c4916 100644 --- a/OlympusServices/app/src/main/res/layout/activity_find_service_provider.xml +++ b/OlympusServices/app/src/main/res/layout/activity_find_service_provider.xml @@ -108,6 +108,11 @@ android:onClick="Search" android:layout_marginRight="10dp" /> +