Skip to content

Instantly share code, notes, and snippets.

@rafaeltoledo
Last active October 29, 2019 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaeltoledo/da1062b3696196a35b561602a9d1fff7 to your computer and use it in GitHub Desktop.
Save rafaeltoledo/da1062b3696196a35b561602a9d1fff7 to your computer and use it in GitHub Desktop.
Android 05
<?xml version="1.0" encoding="utf-8">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dip">
<ImageView android:id="@+id/icone"
android:layout_wi<dth="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="4dip" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/titulo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:textStyle="bold"
android:singleLine="true"
android:ellipsize="end" />
<TextView android:id="@+id/endereco"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="end" />
</LinearLayout>
</LinearLayout>
package net.rafaeltoledo.restaurante;
import java.util.ArrayList;
import java.util.List;
import net.rafaeltoledo.restaurante.model.Restaurante;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioGroup;
public class ListaRestaurantes extends Activity {
List listaRestaurantes = new ArrayList();
ArrayAdapter adaptador = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button salvar = (Button) findViewById(R.id.salvar);
salvar.setOnClickListener(onSave);
ListView lista = (ListView) findViewById(R.id.restaurantes);
adaptador = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, listaRestaurantes);
lista.setAdapter(adaptador);
}
private OnClickListener onSave = new OnClickListener() {
public void onClick(View arg0) {
Restaurante r = new Restaurante();
EditText nome = (EditText) findViewById(R.id.nome);
EditText endereco = (EditText) findViewById(R.id.end);
r.setNome(nome.getText().toString());
r.setEndereco(endereco.getText().toString());
RadioGroup tipos = (RadioGroup) findViewById(R.id.tipos);
switch (tipos.getCheckedRadioButtonId()) {
case R.id.rodizio:
r.setTipo("rodizio");
break;
case R.id.fast_food:
r.setTipo("fast_food");
break;
case R.id.a_domicilio:
r.setTipo("a_domicilio");
break;
}
adaptador.add(r);
}
};
class AdaptadorRestaurante extends ArrayAdapter {
AdaptadorRestaurante() {
super(ListaRestaurantes.this, android.R.layout.simple_list_item_1,
listaRestaurantes);
}
}
}
package net.rafaeltoledo.restaurante;
import java.util.ArrayList;
import java.util.List;
import net.rafaeltoledo.restaurante.model.Restaurante;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
public class ListaRestaurantes extends Activity {
List listaRestaurantes = new ArrayList();
ArrayAdapter adaptador = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button salvar = (Button) findViewById(R.id.salvar);
salvar.setOnClickListener(onSave);
ListView lista = (ListView) findViewById(R.id.restaurantes);
adaptador = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, listaRestaurantes);
lista.setAdapter(adaptador);
}
private OnClickListener onSave = new OnClickListener() {
public void onClick(View arg0) {
Restaurante r = new Restaurante();
EditText nome = (EditText) findViewById(R.id.nome);
EditText endereco = (EditText) findViewById(R.id.end);
r.setNome(nome.getText().toString());
r.setEndereco(endereco.getText().toString());
RadioGroup tipos = (RadioGroup) findViewById(R.id.tipos);
switch (tipos.getCheckedRadioButtonId()) {
case R.id.rodizio:
r.setTipo("rodizio");
break;
case R.id.fast_food:
r.setTipo("fast_food");
break;
case R.id.a_domicilio:
r.setTipo("a_domicilio");
break;
}
adaptador.add(r);
}
};
class AdaptadorRestaurante extends ArrayAdapter {
AdaptadorRestaurante() {
super(ListaRestaurantes.this, android.R.layout.simple_list_item_1,
listaRestaurantes);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View linha = convertView;
if (linha == null) {
LayoutInflater inflater = getLayoutInflater();
linha = inflater.inflate(R.layout.linha, null);
}
Restaurante r = listaRestaurantes.get(position);
((TextView) linha.findViewById(R.id.titulo)).setText(r.getNome());
((TextView) linha.findViewById(R.id.endereco)).setText(r.getEndereco());
ImageView icone = (ImageView) linha.findViewById(R.id.icone);
if (r.getTipo().equals("rodizio")) {
icone.setImageResource(R.drawable.rodizio);
} else if (r.getTipo().equals("fast_food")) {
icone.setImageResource(R.drawable.fast_food);
} else {
icone.setImageResource(R.drawable.entrega);
}
return linha;
}
}
}
package net.rafaeltoledo.restaurante;
import java.util.ArrayList;
import java.util.List;
import net.rafaeltoledo.restaurante.model.Restaurante;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
public class ListaRestaurantes extends Activity {
List listaRestaurantes = new ArrayList();
ArrayAdapter adaptador = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button salvar = (Button) findViewById(R.id.salvar);
salvar.setOnClickListener(onSave);
ListView lista = (ListView) findViewById(R.id.restaurantes);
adaptador = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, listaRestaurantes);
lista.setAdapter(adaptador);
}
private OnClickListener onSave = new OnClickListener() {
public void onClick(View arg0) {
Restaurante r = new Restaurante();
EditText nome = (EditText) findViewById(R.id.nome);
EditText endereco = (EditText) findViewById(R.id.end);
r.setNome(nome.getText().toString());
r.setEndereco(endereco.getText().toString());
RadioGroup tipos = (RadioGroup) findViewById(R.id.tipos);
switch (tipos.getCheckedRadioButtonId()) {
case R.id.rodizio:
r.setTipo("rodizio");
break;
case R.id.fast_food:
r.setTipo("fast_food");
break;
case R.id.a_domicilio:
r.setTipo(";a_domicilio");
break;
}
adaptador.add(r);
}
};
class AdaptadorRestaurante extends ArrayAdapter {
AdaptadorRestaurante() {
super(ListaRestaurantes.this, android.R.layout.simple_list_item_1,
listaRestaurantes);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View linha = convertView;
if (linha == null) {
LayoutInflater inflater = getLayoutInflater();
linha = inflater.inflate(R.layout.linha, null);
}
Restaurante r = listaRestaurantes.get(position);
((TextView) linha.findViewById(R.id.titulo)).setText(r.getNome());
((TextView) linha.findViewById(R.id.endereco)).setText(r.getEndereco());
ImageView icone = (ImageView) linha.findViewById(R.id.icone);
if (r.getTipo().equals("rodizio")) {
icone.setImageResource(R.drawable.rodizio);
} else if (r.getTipo().equals("fast_food")) {
icone.setImageResource(R.drawable.fast_food);
} else {
icone.setImageResource(R.drawable.entrega);
}
return linha;
}
}
static class ArmazenadorRestaurante {
private TextView nome = null;
private TextView endereco = null;
private ImageView icone = null;
ArmazenadorRestaurante(View linha) {
nome = (TextView) linha.findViewById(R.id.titulo);
endereco = (TextView) linha.findViewById(R.id.endereco);
icone = (ImageView) linha.findViewById(R.id.icone);
}
void popularFormulario(Restaurante r) {
nome.setText(r.getNome());
endereco.setText(r.getEndereco());
if (r.getTipo().equals("rodizio")) {
icone.setImageResource(R.drawable.rodizio);
} else if (r.getTipo().equals("fast_food")) {
icone.setImageResource(R.drawable.fast_food);
} else {
icone.setImageResource(R.drawable.entrega);
}
}
}
}
package net.rafaeltoledo.restaurante;
import java.util.ArrayList;
import java.util.List;
import net.rafaeltoledo.restaurante.model.Restaurante;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
public class ListaRestaurantes extends Activity {
List listaRestaurantes = new ArrayList();
AdaptadorRestaurante adaptador = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button salvar = (Button) findViewById(R.id.salvar);
salvar.setOnClickListener(onSave);
ListView lista = (ListView) findViewById(R.id.restaurantes);
adaptador = new AdaptadorRestaurante();
lista.setAdapter(adaptador);
}
private OnClickListener onSave = new OnClickListener() {
public void onClick(View arg0) {
Restaurante r = new Restaurante();
EditText nome = (EditText) findViewById(R.id.nome);
EditText endereco = (EditText) findViewById(R.id.end);
r.setNome(nome.getText().toString());
r.setEndereco(endereco.getText().toString());
RadioGroup tipos = (RadioGroup) findViewById(R.id.tipos);
switch (tipos.getCheckedRadioButtonId()) {
case R.id.rodizio:
r.setTipo("rodizio");
break;
case R.id.fast_food:
r.setTipo("fast_food");
break;
case R.id.a_domicilio:
r.setTipo("a_domicilio");
break;
}
adaptador.add(r);
}
};
class AdaptadorRestaurante extends ArrayAdapter {
AdaptadorRestaurante() {
super(ListaRestaurantes.this, R.layout.linha,
listaRestaurantes);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View linha = convertView;
ArmazenadorRestaurante armazenador = null;
if (linha == null) {
LayoutInflater inflater = getLayoutInflater();
linha = inflater.inflate(R.layout.linha, parent, false);
armazenador = new ArmazenadorRestaurante(linha);
linha.setTag(armazenador);
} else {
armazenador = (ArmazenadorRestaurante) linha.getTag();
}
armazenador.popularFormulario(listaRestaurantes.get(position));
return linha;
}
}
static class ArmazenadorRestaurante {
private TextView nome = null;
private TextView endereco = null;
private ImageView icone = null;
ArmazenadorRestaurante(View linha) {
nome = (TextView) linha.findViewById(R.id.titulo);
endereco = (TextView) linha.findViewById(R.id.endereco);
icone = (ImageView) linha.findViewById(R.id.icone);
}
void popularFormulario(Restaurante r) {
nome.setText(r.getNome());
endereco.setText(r.getEndereco());
if (r.getTipo().equals("rodizio")) {
icone.setImageResource(R.drawable.rodizio);
} else if (r.getTipo().equals("fast_food")) {
icone.setImageResource(R.drawable.fast_food);
} else {
icone.setImageResource(R.drawable.entrega);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment