Permalink
Browse files

Added a recycler view with cards inside

  • Loading branch information...
1 parent 683f5f6 commit 217f9ec4782f5e93eea7b7637d352f70987b190d @espinchi espinchi committed Apr 24, 2015
@@ -2,12 +2,61 @@
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.androidsx.quizzes.data.QuizProvider;
+import com.androidsx.quizzes.model.Quiz;
+
+import java.util.List;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+
+ RecyclerView rv = (RecyclerView) findViewById(R.id.quiz_list);
+ rv.setLayoutManager(new LinearLayoutManager(this));
+ rv.setAdapter(new QuizListAdapter(new QuizProvider().readQuizzes()));
+ }
+
+ class QuizListAdapter extends RecyclerView.Adapter<QuizViewHolder> {
+ private final List<Quiz> quizzes;
+
+ QuizListAdapter(List<Quiz> quizzes) {
+ this.quizzes = quizzes;
+ }
+
+ @Override
+ public QuizViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
+ final LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
+ final View v = layoutInflater.inflate(R.layout.quiz_card, viewGroup, false);
+ return new QuizViewHolder(v);
+ }
+
+ @Override
+ public void onBindViewHolder(QuizViewHolder quizViewHolder, int i) {
+ quizViewHolder.quizQuestion.setText(quizzes.get(i).getQuestion());
+ }
+
+ @Override
+ public int getItemCount() {
+ return quizzes.size();
+ }
+ }
+
+ class QuizViewHolder extends RecyclerView.ViewHolder {
+ TextView quizQuestion;
+
+ QuizViewHolder(View itemView) {
+ super(itemView);
+ quizQuestion = (TextView) itemView.findViewById(R.id.quiz_question);
+ }
}
}
@@ -0,0 +1,22 @@
+package com.androidsx.quizzes.data;
+
+import com.androidsx.quizzes.model.Quiz;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class QuizProvider {
+
+ /** For now, sample list from http://guesstheemoji-movies-answers.com/level-1/ */
+ public List<Quiz> readQuizzes() {
+ return Arrays.asList(
+ new Quiz("spider, boy walking"),
+ new Quiz("spider, boy walking"),
+ new Quiz("star, gun, bomb"),
+ new Quiz("half moon, boy and girl in love, wolf"),
+ new Quiz("drumstick, rib, game controller"),
+ new Quiz("bride, boy, pow, pow"),
+ new Quiz("cat, boot")
+ );
+ }
+}
@@ -0,0 +1,13 @@
+package com.androidsx.quizzes.model;
+
+public class Quiz {
+ private final String question;
+
+ public Quiz(String question) {
+ this.question = question;
+ }
+
+ public String getQuestion() {
+ return question;
+ }
+}
@@ -2,62 +2,13 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
+ android:padding="@dimen/default_margin_padding"
android:orientation="vertical"
tools:context=".MainActivity">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/hello_world" />
-
- <!-- Sample card. -->
@espinchi
espinchi Apr 25, 2015 Member

We won't need the sample card anymore.

- <android.support.v7.widget.CardView
+ <android.support.v7.widget.RecyclerView
+ android:id="@+id/quiz_list"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/cv">
-
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:padding="16dp" >
-
- <ImageView
- android:id="@+id/person_photo"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentStart="true"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:layout_marginEnd="16dp"
- android:layout_marginRight="16dp"
- android:src="@mipmap/ic_launcher"
- tools:ignore="ContentDescription" />
-
- <TextView
- android:id="@+id/person_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toEndOf="@+id/person_photo"
- android:layout_toRightOf="@+id/person_photo"
- android:layout_alignParentTop="true"
- android:textSize="30sp"
- android:text="Emma Wilson"
- tools:ignore="HardcodedText" />
-
- <TextView
- android:id="@+id/person_age"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toEndOf="@+id/person_photo"
- android:layout_toRightOf="@+id/person_photo"
- android:layout_below="@+id/person_name"
- android:text="23 years old"
- tools:ignore="HardcodedText" />
- </RelativeLayout>
- </android.support.v7.widget.CardView>
+ android:layout_height="match_parent" />
</LinearLayout>
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.v7.widget.CardView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginTop="@dimen/inter_card_half_spacing"
+ android:layout_marginBottom="@dimen/inter_card_half_spacing" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:padding="@dimen/card_padding"
+ tools:background="#22000000">
+
+ <!-- The actual quiz question. -->
+ <TextView
+ android:id="@+id/quiz_question"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="@dimen/default_margin_padding"
+ tools:text="Lo que el viento se llevo"
+ android:textSize="@dimen/quiz_question_text_size" />
+
+ <!-- Bottom panel with fake share buttons. -->
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <TextView
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:gravity="center"
+ android:singleLine="true"
+ android:textSize="16sp"
+ android:text="WhatsApp"
+ tools:ignore="HardcodedText" />
+
+ <TextView
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:gravity="center"
+ android:singleLine="true"
+ android:textSize="16sp"
+ android:text="Copy"
+ tools:ignore="HardcodedText" />
+
+ <TextView
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:gravity="center"
+ android:singleLine="true"
+ android:textSize="16sp"
+ android:text="Others"
+ tools:ignore="HardcodedText" />
+ </LinearLayout>
+ </LinearLayout>
+</android.support.v7.widget.CardView>
@@ -1,5 +1,8 @@
<resources>
- <!-- Default screen margins, per the Android Design guidelines. -->
- <dimen name="activity_horizontal_margin">16dp</dimen>
- <dimen name="activity_vertical_margin">16dp</dimen>
+ <dimen name="default_margin_padding">16dp</dimen>
+
+ <dimen name="inter_card_half_spacing">4dp</dimen>
+ <dimen name="card_padding">8dp</dimen>
+
+ <dimen name="quiz_question_text_size">24sp</dimen>
</resources>
@@ -1,5 +1,3 @@
<resources>
<string name="app_name">Quizzes</string>
-
- <string name="hello_world">Hello world!</string>
</resources>
@@ -1,8 +1,3 @@
<resources>
-
- <!-- Base application theme. -->
- <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
- <!-- Customize your theme here. -->
- </style>
-
+ <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar" />
</resources>

0 comments on commit 217f9ec

Please sign in to comment.