From 6f49545abafb765c32c65d5cbfb91b99739e7802 Mon Sep 17 00:00:00 2001 From: IvanaE Date: Thu, 1 Nov 2018 14:40:25 -0400 Subject: [PATCH] fixed ui elements --- .../olympus/olympusservices/MyAdapter.java | 60 ---------------- .../olympus/olympusservices/ServicesList.java | 70 ++++++++++++++++++- .../res/layout/activity_services_list.xml | 32 +++++++++ .../app/src/main/res/layout/list_item.xml | 3 +- 4 files changed, 103 insertions(+), 62 deletions(-) diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MyAdapter.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MyAdapter.java index fe56680..2855872 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MyAdapter.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MyAdapter.java @@ -8,63 +8,3 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -public class MyAdapter extends RecyclerView.Adapter { - - private Service[] services; - - // 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(Service[] services) { - this.services = services; - } - - // Create new views (invoked by the layout manager) - @NonNull - @Override - public ServicesHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.list_item, parent, false); - ServicesHolder vh = new ServicesHolder(v); - return vh; - } - - // Replace the contents of a view (invoked by the layout manager) - @Override - public void onBindViewHolder(ServicesHolder holder, int position) { - Service service = services[position]; - holder.name.setText(service.getName()); - holder.rate.setText(""+service.getRate()); - - - - } - - // Return the size of your dataset (invoked by the layout manager) - @Override - public int getItemCount() { - return services.length; - } - - class ServicesHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ - - TextView name; - TextView rate; - - public ServicesHolder(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) { - } - - - } - - -} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java index 4f9e008..67b9d7b 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java @@ -1,11 +1,15 @@ package com.uottawa.olympus.olympusservices; +import android.content.Context; +import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.GridView; @@ -39,7 +43,7 @@ public class ServicesList extends AppCompatActivity implements NewServiceDialogF mLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLayoutManager); - mAdapter = new MyAdapter(services); + mAdapter = new MyAdapter(services, this); mRecyclerView.setAdapter(mAdapter); @@ -88,4 +92,68 @@ public class ServicesList extends AppCompatActivity implements NewServiceDialogF this.recreate(); } + public class MyAdapter extends RecyclerView.Adapter { + + private Service[] services; + 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(Service[] services, Context context) { + this.services = services; + } + + // Create new views (invoked by the layout manager) + @NonNull + @Override + public ServicesHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.list_item, parent, false); + ServicesHolder vh = new ServicesHolder(v); + return vh; + } + + // Replace the contents of a view (invoked by the layout manager) + @Override + public void onBindViewHolder(ServicesHolder holder, int position) { + Service service = services[position]; + holder.name.setText(service.getName()); + holder.rate.setText(""+service.getRate()); + + + + } + + // Return the size of your dataset (invoked by the layout manager) + @Override + public int getItemCount() { + return services.length; + } + + class ServicesHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ + + TextView name; + TextView rate; + + public ServicesHolder(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) { + editService(view); + + } + + + } + + + } + } \ No newline at end of file diff --git a/OlympusServices/app/src/main/res/layout/activity_services_list.xml b/OlympusServices/app/src/main/res/layout/activity_services_list.xml index e9742e0..8404298 100644 --- a/OlympusServices/app/src/main/res/layout/activity_services_list.xml +++ b/OlympusServices/app/src/main/res/layout/activity_services_list.xml @@ -24,6 +24,38 @@ android:textSize="20sp" android:layout_marginTop="10dp" app:fontFamily="@font/julius_sans_one" /> + + + + + + + + diff --git a/OlympusServices/app/src/main/res/layout/list_item.xml b/OlympusServices/app/src/main/res/layout/list_item.xml index 9d11ed4..1cd18b4 100644 --- a/OlympusServices/app/src/main/res/layout/list_item.xml +++ b/OlympusServices/app/src/main/res/layout/list_item.xml @@ -1,7 +1,8 @@ + android:layout_height="50dp" + android:clickable="true">