waiting for dbhelper to finish recycler view
This commit is contained in:
parent
5b8b0fdfd2
commit
3bdd8b5ad6
2 changed files with 77 additions and 0 deletions
|
@ -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<MyAdapter.ProviderHolder> {
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,6 +108,11 @@
|
|||
android:onClick="Search"
|
||||
android:layout_marginRight="10dp"
|
||||
/>
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/ServiceProviders"
|
||||
android:scrollbars="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="250dp"/>
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue