Commit e3f4b3f3 by Paktalin

created wine object, set it to adapter

parent 7e09ea6b
package com.example.paktalin.lavina; package com.example.paktalin.lavina;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
...@@ -18,12 +20,23 @@ import android.widget.ListView; ...@@ -18,12 +20,23 @@ import android.widget.ListView;
public class MainActivity extends AppCompatActivity public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener { implements NavigationView.OnNavigationItemSelectedListener {
Bitmap[] winePics;
String[] wineTitles, winePrices;
WineBottle[] wines;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
WineAdapter adapter = new WineAdapter(MainActivity.this); extractWinePics();
extractWineTitles();
extractWinePrices();
setWineArray();
WineAdapter adapter = new WineAdapter(MainActivity.this, wines);
ListView listView = findViewById(R.id.list_view); ListView listView = findViewById(R.id.list_view);
listView.setAdapter(adapter); listView.setAdapter(adapter);
...@@ -50,6 +63,49 @@ public class MainActivity extends AppCompatActivity ...@@ -50,6 +63,49 @@ public class MainActivity extends AppCompatActivity
navigationView.setNavigationItemSelectedListener(this); navigationView.setNavigationItemSelectedListener(this);
} }
private void extractWinePrices() {
winePrices = new String[] {
"€7.90",
"€8.85",
"€13.50",
"€5.74",
"€8.00",
"€15.90",
"€11.50",
"€9.79"};
}
private void setWineArray() {
wines = new WineBottle[8];
for (int i = 0; i < wines.length; i++) {
wines[i] = new WineBottle(wineTitles[i], winePrices[i], winePics[i]);
}
}
private void extractWineTitles() {
wineTitles = new String[] {
"Colli Euganei Bianco Olivetani Ca' Lustra 2015",
"Pecorino Volo Di Berardino 2017",
"Langhe Nebbiolo Bric Cenciurio 2016",
"Grignolino Raniero Castello di Gabiano 2016",
"Le Fattorie Tenuta di Frassineto 2014",
"Doglio La Brugherata 2008",
"Lagrein Hofstätter 2016",
"Vermentino di Sardegna Cala Silente Santadi 2017"};
}
private void extractWinePics() {
winePics = new Bitmap[8];
winePics[0] = BitmapFactory.decodeResource(getResources(), R.drawable.wine1);
winePics[1] = BitmapFactory.decodeResource(getResources(), R.drawable.wine2);
winePics[2] = BitmapFactory.decodeResource(getResources(), R.drawable.wine3);
winePics[3] = BitmapFactory.decodeResource(getResources(), R.drawable.wine4);
winePics[4] = BitmapFactory.decodeResource(getResources(), R.drawable.wine5);
winePics[5] = BitmapFactory.decodeResource(getResources(), R.drawable.wine6);
winePics[6] = BitmapFactory.decodeResource(getResources(), R.drawable.wine7);
winePics[7] = BitmapFactory.decodeResource(getResources(), R.drawable.wine8);
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
......
...@@ -5,6 +5,8 @@ import android.view.LayoutInflater; ...@@ -5,6 +5,8 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/** /**
* Created by Paktalin on 14/05/2018. * Created by Paktalin on 14/05/2018.
...@@ -13,21 +15,22 @@ import android.widget.BaseAdapter; ...@@ -13,21 +15,22 @@ import android.widget.BaseAdapter;
public class WineAdapter extends BaseAdapter { public class WineAdapter extends BaseAdapter {
private LayoutInflater inflater; private LayoutInflater inflater;
private WineBottle[] wines;
WineAdapter(Context context) { WineAdapter(Context context, WineBottle[] wines) {
this.wines = wines;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
} }
@Override @Override
public int getCount() { public int getCount() {
return 8; return wines.length;
} }
@Override @Override
public Object getItem(int position) { public Object getItem(int position) {
return null; return wines[position];
} }
@Override @Override
...@@ -42,6 +45,13 @@ public class WineAdapter extends BaseAdapter { ...@@ -42,6 +45,13 @@ public class WineAdapter extends BaseAdapter {
convertView = inflater.inflate(R.layout.wine_item, null); convertView = inflater.inflate(R.layout.wine_item, null);
} }
WineBottle bottle = (WineBottle)getItem(position);
((TextView)convertView.findViewById(R.id.wine_title)).setText(bottle.getTitle());
((TextView)convertView.findViewById(R.id.wine_price)).setText(bottle.getPrice());
((ImageView)convertView.findViewById(R.id.wine_image)).setImageBitmap(bottle.getImage());
return convertView; return convertView;
} }
} }
package com.example.paktalin.lavina;
import android.graphics.Bitmap;
/**
* Created by Paktalin on 14/05/2018.
*/
class WineBottle {
private String title;
private String price;
private Bitmap image;
WineBottle(String title, String price, Bitmap image) {
this.title = title;
this.price = price;
this.image = image;
}
public String getTitle() {
return title;
}
public String getPrice() {
return price;
}
public Bitmap getImage() {
return image;
}
}
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_toEndOf="@+id/wine_sample"> android:layout_toEndOf="@+id/wine_image"
android:layout_toRightOf="@+id/wine_image">
<TextView <TextView
android:id="@+id/wine_title" android:id="@+id/wine_title"
...@@ -23,7 +24,7 @@ ...@@ -23,7 +24,7 @@
android:layout_marginLeft="20dp" /> android:layout_marginLeft="20dp" />
<TextView <TextView
android:id="@+id/wine_brand" android:id="@+id/wine_price"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/wine_title" android:layout_below="@+id/wine_title"
...@@ -36,7 +37,7 @@ ...@@ -36,7 +37,7 @@
</RelativeLayout> </RelativeLayout>
<ImageView <ImageView
android:id="@+id/wine_sample" android:id="@+id/wine_image"
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="80dp" android:layout_height="80dp"
android:background="@drawable/wine1" android:background="@drawable/wine1"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment