diff --git a/FIUBER/app/src/main/java/com/taller/fiuber/Car.java b/FIUBER/app/src/main/java/com/taller/fiuber/Car.java new file mode 100644 index 0000000..b851ae8 --- /dev/null +++ b/FIUBER/app/src/main/java/com/taller/fiuber/Car.java @@ -0,0 +1,20 @@ +package com.taller.fiuber; + +public class Car { + + String modelo; + Integer imagen; + + public Car(String modelo, Integer imagen) { + this.modelo = modelo; + this.imagen = imagen; + } + + public String getModelo() { + return modelo; + } + + public Integer getImagen() { + return imagen; + } +} diff --git a/FIUBER/app/src/main/java/com/taller/fiuber/CarAdapter.java b/FIUBER/app/src/main/java/com/taller/fiuber/CarAdapter.java index 91e8d97..c0fe40c 100644 --- a/FIUBER/app/src/main/java/com/taller/fiuber/CarAdapter.java +++ b/FIUBER/app/src/main/java/com/taller/fiuber/CarAdapter.java @@ -12,15 +12,23 @@ public class CarAdapter extends BaseAdapter { private Context context; private List images; + private List autos; + /* public CarAdapter(Context context, List images) { this.context = context; this.images = images; + }*/ + + public CarAdapter(Context context, List autos) { + this.context = context; + this.autos = autos; } @Override public int getCount() { - return images.size(); + //return images.size(); + return autos.size(); } @Override @@ -33,12 +41,21 @@ public long getItemId(int i) { return i; } + public Integer getCarImage(int i){ + return autos.get(i).getImagen(); + } + + public String getCarTitle(int i){ + return autos.get(i).getModelo(); + } + @Override public View getView(int i, View view, ViewGroup viewGroup) { if(view == null){ view = LayoutInflater.from(context).inflate(R.layout.car_item, viewGroup, false); } - view.setBackgroundResource(images.get(i)); + //view.setBackgroundResource(images.get(i)); + view.setBackgroundResource(getCarImage(i)); return view; } } diff --git a/FIUBER/app/src/main/java/com/taller/fiuber/CarsActivity.java b/FIUBER/app/src/main/java/com/taller/fiuber/CarsActivity.java index 8c82d19..0e08bfb 100644 --- a/FIUBER/app/src/main/java/com/taller/fiuber/CarsActivity.java +++ b/FIUBER/app/src/main/java/com/taller/fiuber/CarsActivity.java @@ -25,28 +25,29 @@ public class CarsActivity extends AppCompatActivity { InfiniteCardView infiniteCardView; CarAdapter carAdapter; List images = new ArrayList<>(); + List autos = new ArrayList<>(); int indice; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_cars_acctivity); + setContentView(R.layout.activity_cars); btnNext = (Button) findViewById(R.id.cars_next); btnSelect = (Button) findViewById(R.id.cars_select); infiniteCardView = (InfiniteCardView) findViewById(R.id.cars_view); carsTitle = (TextView) findViewById(R.id.cars_title); - //Seteo el primer nombre de titulo - carsTitle.setText("Auto 0"); - //Creo la lista de autos junto con su indice indice = 0; - images.add(R.drawable.auto1); - images.add(R.drawable.auto2); - images.add(R.drawable.auto3); + Car auto1 = new Car("Auto naranja", R.drawable.auto1); + Car auto2 = new Car("Auto rojo", R.drawable.auto2); + Car auto3 = new Car("Auto azul", R.drawable.auto3); + autos.add(auto1); + autos.add(auto2); + autos.add(auto3); - carAdapter = new CarAdapter(this, images); + carAdapter = new CarAdapter(this, autos); infiniteCardView.setClickable(true); infiniteCardView.setAnimType(InfiniteCardView.ANIM_TYPE_FRONT); infiniteCardView.setAnimInterpolator(new LinearInterpolator()); @@ -55,6 +56,10 @@ protected void onCreate(Bundle savedInstanceState) { infiniteCardView.setZIndexTransformerToBack(new DefaultZIndexTransformerCommon()); infiniteCardView.setAdapter(carAdapter); + //Seteo el nombre del primer a auto + String nombrePrimero = carAdapter.getCarTitle(indice); + carsTitle.setText(nombrePrimero); + //Click en "Siguiente" btnNext.setOnClickListener(new View.OnClickListener() { @Override @@ -65,8 +70,7 @@ public void onClick(View view) { } else { indice --; } - Log.v(TAG, "Auto "+ indice); - carsTitle.setText("Auto "+ indice); + carsTitle.setText(carAdapter.getCarTitle(indice)); } }); @@ -74,7 +78,7 @@ public void onClick(View view) { btnSelect.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Log.v(TAG, "Auto "+ indice +" seleccionado."); + Log.v(TAG, carAdapter.getCarTitle(indice) +" seleccionado."); } }); diff --git a/FIUBER/app/src/main/res/layout/activity_cars.xml b/FIUBER/app/src/main/res/layout/activity_cars.xml new file mode 100644 index 0000000..38a4bbc --- /dev/null +++ b/FIUBER/app/src/main/res/layout/activity_cars.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + +