-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
149 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
10 changes: 5 additions & 5 deletions
10
...dg/hareshkh/lectureassignment/movies.java → ...areshkh/lectureassignment/MovieClass.java
This file contains 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
72 changes: 72 additions & 0 deletions
72
app/src/main/java/com/sdsmdg/hareshkh/lectureassignment/MoviesAdapter.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.sdsmdg.hareshkh.lectureassignment; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import java.util.List; | ||
|
||
public class MoviesAdapter extends RecyclerView.Adapter<MoviesAdapter.ViewHolder> { | ||
|
||
private List<MovieClass> movies; | ||
private Context ctx; | ||
|
||
public MoviesAdapter(List<MovieClass> movies, Context ctx) { | ||
this.movies = movies; | ||
this.ctx = ctx; | ||
} | ||
|
||
public Context getCtx() { | ||
return ctx; | ||
} | ||
|
||
public class ViewHolder extends RecyclerView.ViewHolder { | ||
|
||
public TextView movieName; | ||
public TextView movieYear; | ||
public ImageView movieImage; | ||
|
||
public ViewHolder(View itemView) { | ||
super(itemView); | ||
movieName= (TextView) itemView.findViewById(R.id.movie_name); | ||
movieYear= (TextView) itemView.findViewById(R.id.movie_year); | ||
movieImage= (ImageView) itemView.findViewById(R.id.movie_image); | ||
} | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
LayoutInflater inflater=LayoutInflater.from(getCtx()); | ||
|
||
View movieView= inflater.inflate(R.layout.row_layout,parent,false); | ||
|
||
ViewHolder mHolder= new ViewHolder(movieView); | ||
return mHolder; | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder holder, int position) { | ||
|
||
MovieClass movie=movies.get(position); | ||
holder.movieName.setText(movie.getTitle()); | ||
holder.movieYear.setText(movie.getYear()); | ||
|
||
Bitmap bitmap= BitmapFactory.decodeResource(getCtx().getResources(), | ||
This comment has been minimized.
Sorry, something went wrong. |
||
Utils.getImageResourceFromString(movie.getImageResId(),getCtx())); | ||
Bitmap bMapScaled=Utils.scaleToFitWidth(bitmap, (int) Utils.convertToPixel(500,getCtx())); | ||
|
||
holder.movieImage.setImageBitmap(bMapScaled); | ||
|
||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return movies.size(); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<android.support.v7.widget.CardView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:card_view="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="70dp" | ||
android:layout_margin="16dp" | ||
card_view:cardCornerRadius="8dp" | ||
card_view:cardElevation="8dp" | ||
android:clickable="true" | ||
android:foreground="?android:attr/selectableItemBackground"> | ||
|
||
<android.support.v7.widget.CardView | ||
|
||
<RelativeLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
</LinearLayout> | ||
android:layout_height="match_parent"> | ||
|
||
<ImageView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
android:scaleType="centerCrop" | ||
android:id="@+id/movie_image" /> | ||
|
||
<LinearLayout | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:text="Movie" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_weight="1" | ||
android:textSize="16dp" | ||
android:textStyle="bold" | ||
android:gravity="center" | ||
android:id="@+id/movie_name" /> | ||
|
||
<TextView | ||
android:text="Year" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_weight="1" | ||
android:gravity="center" | ||
android:id="@+id/movie_year" /> | ||
|
||
|
||
</LinearLayout> | ||
</RelativeLayout> | ||
|
||
</android.support.v7.widget.CardView> |
This is a very heavy task that you are doing here on main thread and that's why your RecyclerView hangs on scrolling.
There are two possible solutions here:
Links: Picasso, Glide, Universal Image Loader.
All are great but I personally prefer Universal Image Loader.