Added some functionality

This commit is contained in:
RemoMeijer
2020-12-14 12:05:32 +01:00
parent 63c49c40d7
commit 16b9b15856
3 changed files with 32 additions and 13 deletions

View File

@@ -1,12 +1,15 @@
package com.a1.nextlocation.recyclerview;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Location;
import java.util.List;
@@ -23,31 +26,41 @@ public class LocationAdapter extends RecyclerView.Adapter<LocationAdapter.Locati
class LocationViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView locationName;
public LocationViewHolder(@NonNull View itemView) {
super(itemView);
this.locationName = itemView.findViewById(R.id.location_name);
}
@Override
public void onClick(View view) {
clickListener.onItemClick(getAdapterPosition());
}
public void setTextViewText(String text){
locationName.setText(text);
}
}
public LocationAdapter(Context context, List<Location> location, CouponAdapter.OnItemClickListener listener){
appContext = context;
locationList = location;
clickListener = listener;
this.appContext = context;
this.locationList = location;
this.clickListener = listener;
}
@NonNull
@Override
public LocationAdapter.LocationViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_location, parent, false);
LocationViewHolder viewHolder = new LocationViewHolder(itemView);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull LocationAdapter.LocationViewHolder holder, int position) {
Location location = locationList.get(position);
holder.setTextViewText(location.getName());
}
@Override

View File

@@ -1,14 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".fragments.LocationFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
android:layout_height="match_parent"/>
</FrameLayout>

View File

@@ -1,14 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".fragments.LocationDetailFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
android:id="@+id/location_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LocationName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.296" />
</FrameLayout>