-
-
Save jemaf/130e570285c6a6d6991bf1a698837315 to your computer and use it in GitHub Desktop.
Segunda versão do adapter customizado utilizado no app Android EATI 2016.
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
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
android:paddingBottom="@dimen/activity_vertical_margin"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/lbl_movie_name" | |
android:textSize="20dp" | |
android:text="My Movie"/> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentEnd="true" | |
android:id="@+id/lbl_movie_grade" | |
android:textSize="20dp" | |
android:text="5"/> | |
<TextView | |
android:layout_marginTop="5dp" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_below="@id/lbl_movie_name" | |
android:id="@+id/lbl_movie_comment" | |
android:text="lorem ipsum comment"/> | |
</RelativeLayout> |
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
package edu.ifmg.eati.movieme; | |
import android.content.Context; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.BaseAdapter; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
import edu.ifmg.eati.movieme.model.Movie; | |
/** | |
* Created by edumontandon on 5/17/16. | |
*/ | |
public class MoviesAdapter extends BaseAdapter { | |
// Lista de filmes a serem exibidos | |
private ArrayList<Movie> movies; | |
private Context context; | |
public MoviesAdapter(Context context) { | |
this.context = context; | |
this.movies = new ArrayList<>(); | |
loadMovies(); | |
} | |
private void loadMovies() { | |
this.movies.add(new Movie("Star Wars", 7, "Filme clássico")); | |
this.movies.add(new Movie("Senhor dos Anéis", 10, "ÉPICO!!")); | |
this.movies.add(new Movie("A Origem", 9, "Mind Blowing")); | |
this.movies.add(new Movie("Pulp Fiction", 8, "Obra prima")); | |
this.movies.add(new Movie("Se eu fosse você", 3, "Se eu fosse você... não pederia seu tempo")); | |
} | |
@Override | |
public int getCount() { | |
return this.movies.size(); | |
} | |
@Override | |
public Object getItem(int position) { | |
return this.movies.get(position); | |
} | |
@Override | |
public long getItemId(int position) { | |
return position; | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
// obtem o filme desejado | |
Movie movie = this.movies.get(position); | |
View view = LayoutInflater.from(this.context).inflate(R.layout.adapter_movies, parent, false); | |
TextView lblName = (TextView) view.findViewById(R.id.lbl_movie_name); | |
TextView lblGrade = (TextView) view.findViewById(R.id.lbl_movie_grade); | |
TextView lblComment = (TextView) view.findViewById(R.id.lbl_movie_comment); | |
lblName.setText(movie.getName()); | |
lblGrade.setText(String.valueOf(movie.getRating())); | |
lblComment.setText(movie.getComment()); | |
return view; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment