Inicio » Blog » Android

27 junio, 2020

¿Como hacer una app Android para Restaurante? II

SEGUNDA PARTE: Desarrollo de un aplicativo móvil en Android cuya finalidad es mostrar información de un restaurante a los usuarios

¿Como hacer una app Android para Restaurante?  II

Suscríbete a nuestro canal en Youtube

Suscríbirse

4 DETALLE DEL PLATO:

Mostramos una foto , el nombre del plato, el precio y una descripción.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:gravity="center_horizontal"
 tools:context=".ProductoActivity">
 <ImageView
 android:id="@+id/foto"
 android:adjustViewBounds="true"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <ImageView
 android:src="@drawable/cinta"
 android:adjustViewBounds="true"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <TextView
 android:id="@+id/nombre"
 android:gravity="center_horizontal"
 android:text="NOMBRE"
 android:textSize="18dp"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <TextView
 android:id="@+id/precio"
 android:gravity="center_horizontal"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <View
 android:layout_width="match_parent"
 android:layout_height="1dp"/>
 <TextView
 android:id="@+id/descripcion"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
</LinearLayout>

Java

package apptiva.arequipa.huaca;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
public class ProductoActivity extends AppCompatActivity {
 private ImageView _foto;
 private TextView _nombre, _descripcion ,_precio;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_producto);
 _foto = findViewById(R.id.foto);
 _nombre = findViewById(R.id.nombre);
 _descripcion= findViewById(R.id.descripcion);
 _precio = findViewById(R.id.precio);
 _nombre.setText(getIntent().getExtras().getString("nombre"));

_descripcion.setText(getIntent().getExtras().getString("descripcion"))
;
 _precio.setText(getIntent().getExtras().getString("precio"));

_foto.setImageResource(getResources().getIdentifier(getIntent().getExt
ras().getString("foto"), "drawable", getPackageName()));
 }
}

5 SECCIÓN BEBIDAS:

Inflamos un GridView con su evento onclickListener para mostrar el detalle del ítem seleccionado al igual que la sección platos.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:orientation="vertical"
 android:background="@color/colorAccent"
 android:layout_height="match_parent"
 tools:context=".BebidasActivity">
 <ImageView
 android:src="@drawable/cinta"
 android:adjustViewBounds="true"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <ListView
 android:id="@+id/listView"
 android:layout_margin="20dp"
 android:dividerHeight="10dp"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="horizontal"
 android:gravity="center_vertical"
 android:layout_marginBottom="5dp"
 android:layout_width="match_parent"
 android:background="@color/colorWhite"
 android:layout_height="wrap_content">
 <ImageView
 android:layout_weight="1"
 android:id="@+id/foto"
 android:adjustViewBounds="true"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <LinearLayout
 android:orientation="vertical"
 android:layout_weight="1"
 android:padding="10dp"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">
 <TextView
 android:id="@+id/nombre"
 android:textStyle="bold"
 android:textSize="18dp"
 android:text="NOMBRE"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <TextView
 android:id="@+id/precio"
 android:text="0.00"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 </LinearLayout>
</LinearLayout

JAVA:

package apptiva.arequipa.huaca;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
public class BebidasActivity extends AppCompatActivity {
 ListView listaBebidas;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_bebidas);
 setTitle("PLATOS");
 listaBebidas = findViewById(R.id.listView);
final ArrayList<Bebida> arrayList = new ArrayList<>();
 arrayList.add(new Bebida("Chicha de Jora","bebida_1",
"8.00","Se hace a base de maíz como la chicha morada, pero se usa el
maíz de jora o maíz malteado. Su proceso de elaboración es lento,
durante varios días, por lo que vale mucho la pena probarla en
restaurantes tradicionales."));
 arrayList.add(new Bebida("Pisco Sour","bebida_2",
"12.00","Este trago insignia es una de las bebidas típicas del Perú.
Se prepara con pisco, claras de huevo, jarabe de goma, limón y
hielo."));
 arrayList.add(new Bebida("Chilcano","bebida_3",
"10.00","Fresco y fácil de preparar, combina pisco, hielo, limón y
Ginger Ale. Algunos le agregan jarabe de goma para mayor dulzor, y
amargo de Angostura."));
 arrayList.add(new Bebida("Chicha Morada","bebida_4",
"24.00","Originaria de los Andes, se hace con maíz morado, cáscaras de
piña, membrillo, canela, clavos de olor, limón, azúcar y frutas
picadas."));
 AdapterBebidas adapterBebida = new AdapterBebidas(arrayList,
this);
 listaBebidas.setAdapter(adapterBebida);
 listaBebidas.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
 @Override
 public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
 startActivity(new
Intent(getApplicationContext(),ProductoActivity.class)

.putExtra("nombre",arrayList.get(position).getNombre())

.putExtra("foto",arrayList.get(position).getFoto())

.putExtra("precio",arrayList.get(position).getPrecio())

.putExtra("descripcion",arrayList.get(position).getDescripcion())
 );
 }
 });
 }
 public class AdapterBebidas extends BaseAdapter {
 ArrayList<Bebida> bebidas;
 Context context;
 public AdapterBebidas(ArrayList<Bebida> p, Context c){
 this.bebidas =p;
 this.context = c;
 }@Override
 public int getCount() {
 return bebidas.size();
 }
 @Override
 public Object getItem(int position) {
 return bebidas.get(position);
 }
 @Override
 public long getItemId(int position) {
 return 0;
 }
 @Override
 public View getView(int position, View convertView, ViewGroup
parent) {
 convertView =
LayoutInflater.from(context).inflate(R.layout.bebidas, parent, false);
 Bebida bebida = bebidas.get(position);
 TextView _nombre = convertView.findViewById(R.id.nombre);
 TextView _precio = convertView.findViewById(R.id.precio);
 ImageView _foto = convertView.findViewById(R.id.foto);
 _nombre.setText(bebida.getNombre());
 _precio.setText("S/. "+bebida.getPrecio());

_foto.setImageResource(getResources().getIdentifier(bebida.getFoto(),
"drawable", getPackageName()));
 return convertView;
 }
 }
public class Bebida{
 private String nombre;
 private String foto;
 private String precio;
 private String descripcion;
 public Bebida(String nombre, String foto, String precio,
String descripcion) {
 this.nombre = nombre;
 this.foto = foto;
 this.precio = precio;
 this.descripcion = descripcion;
 }
 public String getDescripcion() {
 return descripcion;
 }
 public String getPrecio() {
 return precio;
 }
 public String getNombre() {
 return nombre;
 }
 public String getFoto() {
 return foto;
 }
 }
}

6 SECCIÓN LOCALES

Muestra una lista de locales, se detalla con linearLayout para cada local, se muestra una foto, horario de atención y dirección.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 android:background="@color/colorAccent"
 tools:context=".LocalesActivity">
 <ImageView
 android:src="@drawable/cinta"
 android:adjustViewBounds="true"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <TextView
 android:textSize="13dp"
 android:gravity="center_horizontal"
 android:text="Conozca nuestros diferentes locales más cercanos
a Ud."
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <LinearLayout
 android:orientation="horizontal"
 android:background="@color/colorPrimary"
 android:padding="5dp"
 android:layout_margin="5dp"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">
 <ImageView
 android:layout_weight="1"
 android:src="@drawable/local_1"
 android:adjustViewBounds="true"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <TextView
 android:layout_weight="1"
android:padding="10dp"
 android:textSize="12dp"
 android:textColor="@color/colorWhite"
 android:text="DIRECCIÓN: Av. Las Colmenas 234\n ATENCIÓN:
Lunes a Viernes 12:00m 8:00pm "
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 </LinearLayout>
 <LinearLayout
 android:orientation="horizontal"
 android:background="@color/colorPrimary"
 android:padding="5dp"
 android:layout_margin="5dp"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">
 <ImageView
 android:layout_weight="1"
 android:src="@drawable/local_2"
 android:adjustViewBounds="true"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <TextView
 android:layout_weight="1"
 android:padding="10dp"
 android:textSize="12dp"
 android:textColor="@color/colorWhite"
 android:text="DIRECCIÓN: Av. Las Colmenas 234\n ATENCIÓN:
Lunes a Viernes 12:00m 8:00pm "
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 </LinearLayout>
 <LinearLayout
 android:orientation="horizontal"
 android:background="@color/colorPrimary"
 android:padding="5dp"
 android:layout_margin="5dp"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">
 <ImageView
 android:layout_weight="1"
 android:src="@drawable/local_3"
 android:adjustViewBounds="true"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 <TextView
 android:layout_weight="1"
 android:textSize="12dp"
 android:padding="10dp"
 android:textColor="@color/colorWhite"
 android:text="DIRECCIÓN: Av. Las Colmenas 234\n ATENCIÓN:
Lunes a Viernes 12:00m 8:00pm "
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 </LinearLayout>
</LinearLayout>

JAVA:

package apptiva.arequipa.huaca;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class LocalesActivity extends AppCompatActivity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_locales);
 setTitle("LOCALES");
 }
}

 


Leido 2565 veces

Compartir link del tutorial con tus amigos


Android Básico App Restaurante Android Básico App Restaurante

Curso Android Básico para desarrollar una app para un restaurante.

Descarga del código fuente

USD 10.00

Android PHP MySql App Restaurant Android PHP MySql App Restaurant

Curso Android, PHP y MySql App Restaurant con Pedidos Delivery

Descarga del código fuente

USD 12.00

Aprende más sobre Android

Cursos de programación

Codea Codea App

México, Colombia, España, Venezuela, Argentina, Bolivia, Perú

© Todos los derechos reservados Codea App | ...de frente al código!!! | 2020 - 2023