Boa noite pessoal, estou querendo criar um MVC no Android, alguém tem algum exemplo?
Gostaria de criar uma classe com os métodos INSERIR, DELETAR, ETC…
Obs: Usando o SQLite.
obrigado.
[quote=Java_Terminator]Boa noite pessoal, estou querendo criar um MVC no Android, alguém tem algum exemplo?
Gostaria de criar uma classe com os métodos INSERIR, DELETAR, ETC…
Obs: Usando o SQLite.
obrigado.
[/quote]
E já tens algo implementado?
Mostre para nós como vc começou…
[code]package br.may.utilpoint;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import android.util.Log;
public class Conexao {
private static final String CATEGORIA = "teste";
private static final String URLCategoria = "http://10.0.2.2/utilpoint/android/categoria.php";
private static final String URLEstabelecimento = "http://10.0.2.2/utilpoint/android/estabelecimento.php";
private static final String URLEndereco = "http://10.0.2.2/utilpoint/android/endereco.php";
private static final String URLSugestao = "http://10.0.2.2/utilpoint/android/sugestao.php";
private static List<String> categorias = new ArrayList<String>();
private static List<String> lista = new ArrayList<String>();
private static String endereco;
private static String retornoSugestao;
private static String[] estabelecimentos;
public static List<String> buscarCategoria() {
try{
URL myURL = new URL(URLCategoria);
URLConnection ucon = myURL.openConnection();
InputStream in = ucon.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
categorias.clear();
String line = null;
while ((line = reader.readLine()) != null) {
categorias.add(line);
}
} catch (IOException ioe) {
Log.i(CATEGORIA, "IOException " + ioe);
}
return categorias;
}
public static String buscarEndereco(String nome) {
try{
nome = nome.replace(" ","%20");
URL myURL = new URL(URLEndereco + "?nome=" + nome);
Log.i(CATEGORIA, "URLEndereco " + myURL);
URLConnection ucon = myURL.openConnection();
InputStream in = ucon.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
endereco = reader.readLine();
} catch (IOException ioe) {
Log.i(CATEGORIA, "IOException " + ioe);
}
return endereco;
}
public static String[] buscarEstabelecimento(String cat) {
try{
cat = cat.replace(" ","%20");
URL myURL = new URL(URLEstabelecimento + "?categoria=" + cat);
URLConnection ucon = myURL.openConnection();
InputStream in = ucon.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
lista.clear();
String line = null;
while ((line = reader.readLine()) != null) {
lista.add(line);
}
estabelecimentos = (String[]) lista.toArray (new String[lista.size()]);
} catch (IOException ioe) {
Log.i(CATEGORIA, "IOException " + ioe);
}
return estabelecimentos;
}
public static String gravarSugestao(String nome, String email, String descricao) {
try{
nome = nome.replace(" ","%20");
email = email.replace(" ","%20");
descricao = descricao.replace(" ","%20");
URL myURL = new URL(URLSugestao + "?nome=" + nome + "&email=" + email + "&descricao=" + descricao);
URLConnection ucon = myURL.openConnection();
InputStream in = ucon.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
retornoSugestao = reader.readLine();
}
catch(Exception ex){
Log.i(CATEGORIA, "Exception " + ex);
}
return retornoSugestao;
}
}[/code]
[code]package br.may.utilpoint;
import java.util.List;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Categoria extends ListActivity implements Runnable{
private ProgressDialog barra;
private List<String> categorias;
private ArrayAdapter<String> listaCategorias;
@Override
public void onCreate(Bundle icicle){
super.onCreate(icicle);
inicia();
}
public void inicia() {
barra = ProgressDialog.show(this, "Aguarde", "Gerando Lista de Categorias...", true, false);
Thread thread = new Thread(this);
thread.start();
}
@Override
public void run() {
categorias = Conexao.buscarCategoria();
listaCategorias = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, categorias);
handler.sendEmptyMessage(0);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id){
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
String item = o.toString();
Intent myIntent = new Intent(this, Mapa.class);
Bundle parametro = new Bundle();
parametro.putString("categoria", item);
myIntent.putExtras(parametro);
startActivity(myIntent);
}
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
barra.dismiss();
setListAdapter(listaCategorias);
}
};
}[/code]