Created
August 14, 2019 06:39
-
-
Save SurajBahadur/ce66dbee7939954f38d57c959e026add to your computer and use it in GitHub Desktop.
Setting recylerview to contains 3 times in every screen size devices.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:id="@+id/clItem" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="1dp"> | |
<ImageView | |
android:id="@+id/ivLocationImage" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:scaleType="fitXY" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<RelativeLayout | |
android:layout_height="match_parent" | |
android:id="@+id/relative_holder" | |
android:layout_width="match_parent" | |
android:background="@mipmap/gradient_back" | |
android:padding="8dp" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent"> | |
<ImageView | |
android:layout_width="@dimen/_30sdp" | |
android:layout_height="@dimen/_30sdp" | |
android:layout_alignParentRight="true" | |
android:layout_marginRight="@dimen/_5sdp" | |
android:visibility="gone" | |
android:id="@+id/iv_fav"/> | |
<com.app.realestate.utils.views.NexaBoldTextView | |
android:id="@+id/tvLocation" | |
android:textSize="@dimen/_12ssp" | |
android:layout_width="wrap_content" | |
android:layout_above="@id/tvPrice" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="@dimen/_8sdp" | |
android:text="Watteren" | |
android:textColor="@android:color/white" | |
android:textStyle="bold" /> | |
<com.app.realestate.utils.views.NexaBoldTextView | |
android:id="@+id/tvPrice" | |
android:textSize="@dimen/_12ssp" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_above="@id/tvPriceValue" | |
android:layout_marginTop="@dimen/_2sdp" | |
android:text="4 beds,2 baths" | |
android:textColor="@android:color/white" | |
android:textStyle="bold" /> | |
<com.app.realestate.utils.views.NexaBoldTextView | |
android:id="@+id/tvPriceValue" | |
android:textSize="@dimen/_12ssp" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:layout_marginTop="@dimen/_2sdp" | |
android:text="€285.00" | |
android:textColor="@android:color/white" | |
android:textStyle="bold" /> | |
<com.app.realestate.utils.views.NexaBoldTextView | |
android:id="@+id/tvCityName" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentRight="true" | |
android:layout_alignParentBottom="true" | |
android:layout_marginTop="@dimen/_2sdp" | |
android:text="2000-xyz" | |
android:textColor="@android:color/white" | |
android:textSize="@dimen/_12ssp" | |
android:textStyle="bold" /> | |
</RelativeLayout> | |
</android.support.constraint.ConstraintLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.app.demo.adapter | |
import android.app.Activity | |
import android.content.Context | |
import android.support.constraint.ConstraintLayout | |
import android.support.v7.widget.RecyclerView | |
import android.util.DisplayMetrics | |
import android.util.Log | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import com.app.demo.R | |
import com.app.demo.callBack.ItemSelectedListener | |
import com.app.demo.callBack.RecyclerBottomReached | |
import com.app.demo.pojo.getproperties.Properties_list | |
import com.google.gson.Gson | |
import com.squareup.picasso.Picasso | |
import kotlinx.android.synthetic.main.item_home.view.* | |
class MyAdapter(private var myDataset: MutableList<Properties_list>, private var activity: Context?, | |
private var onItemClicked: ItemSelectedListener?,private var bottomReached: RecyclerBottomReached?) : RecyclerView.Adapter<MyAdapter.MyViewHolder>() { | |
class MyViewHolder(val layout: ConstraintLayout) : RecyclerView.ViewHolder(layout) | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { | |
val textView = LayoutInflater.from(parent.context).inflate(R.layout.item_home, parent, false) as ConstraintLayout | |
return MyViewHolder(textView) | |
} | |
// Replace the contents of a view (invoked by the layout manager) | |
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { | |
val displayMetrics = DisplayMetrics() | |
(activity as Activity).windowManager.defaultDisplay.getMetrics(displayMetrics) | |
val height = displayMetrics.heightPixels | |
holder.layout.layoutParams.height = height / 3 | |
if(myDataset[position].property_photos.size>0) { | |
Picasso.get().load(myDataset[position].property_photos[0].image_url).into(holder.layout.ivLocationImage) | |
} | |
holder.layout.tvLocation.text = myDataset[position].property_streetname | |
if(!myDataset[position].property_bedrooms.equals("--") && (!myDataset[position].property_bathrooms.equals("--"))) { | |
holder.layout.tvPrice.text = myDataset[position].property_bedrooms + " " + (activity as Activity).resources.getString(R.string.beds) + " " + myDataset[position].property_bathrooms + " " + (activity as Activity).resources.getString(R.string.baths) | |
}else{ | |
holder.layout.tvPrice.visibility= View.GONE | |
} | |
if ((myDataset[position].property_price.equals("")) || (myDataset[position].property_price.equals("0"))) { | |
holder.layout.tvPriceValue.text = (activity as Activity).resources.getString(R.string.no_price_available) | |
} else { | |
holder.layout.tvPriceValue.text = (activity as Activity).resources.getString(R.string.currency) + myDataset[position].property_price | |
} | |
holder.layout.tvCityName.text = myDataset[position].property_display_city | |
holder.layout.ivLocationImage.setOnClickListener { | |
Log.d("Selected", " " + myDataset[position]); | |
val gson = Gson() | |
val name = gson.toJson(myDataset[position]) | |
onItemClicked?.selectedItem(name, position) | |
} | |
if (position==(myDataset.size-1)){ | |
var count: Int= 0 | |
count +=1 | |
bottomReached!!.bottomReached(count.toString()) | |
} | |
} | |
// Return the size of your dataset (invoked by the layout manager) | |
override fun getItemCount() = myDataset.size | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment