0
From now on I appreciate the understanding of all because I am not very experienced.I am with an error when loading the customer data from a list I want that, when clicking on add customer, I come the customer name in the customer field and so with seller and product. But when I click the add client button it opens the list screen, I give an onClickListner on the client line and comes the order screen without the client name in the client field
Application registration screen code:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import br.gestaoBd.BancoDeDados.PedidoDao;
import br.gestaoBd.BancoDeDados.PedidoItensDao;
import br.gestaoBd.Beans.Pedido;
import br.gestaoBd.Beans.ItemDoPedido;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Locale;
public class CadPedido extends Activity implements AdapterView.OnItemLongClickListener, OnItemClickListener {
static Pedido pedido;
static ArrayList<ItemDoPedido> itensDoPedido;
EditText ed1Id, ed1Cliente, ed1Vendedor, ed1Data;
PedidoDao pedDao;
ListView lista;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.cad_pedido);
ed1Id = (EditText) findViewById(R.id.cadEd1Id);
ed1Cliente = (EditText) findViewById(R.id.cadEd1Cliente);
ed1Vendedor = (EditText) findViewById(R.id.cadEd1Vendedor);
ed1Data = (EditText) findViewById(R.id.cadEd1Data);
lista= (ListView) findViewById(R.id.listview);
Button btAdicionarCliente = (Button) findViewById(R.id.btAdicionarCliente);
btAdicionarCliente.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(CadPedido.this,
ListClientes.class);
startActivity(intent);
}
});
Button btAdicionarVendedor = (Button) findViewById(R.id.btAdicionarVendedor);
btAdicionarVendedor.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(CadPedido.this,
ListVendedor.class);
startActivity(intent);
}
});
Button btAdicionarProduto = (Button) findViewById(R.id.btAdicionarProduto);
btAdicionarProduto.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(CadPedido.this,
ListProdutos.class);
startActivity(intent);
}
});
}
public static Pedido getPedido() {
if (pedido == null) {
pedido = new Pedido();
}
return pedido;
}
public static ArrayList<ItemDoPedido> getItensDoPedido() {
if (itensDoPedido == null) {
Log.i("AULA", "cRIOU ITENS DO PEDIDO");
itensDoPedido = new ArrayList<ItemDoPedido>();
}
return itensDoPedido;
}
public static double getTotal() {
double total = 0.00;
Log.i("AULA", "itens adiconados =" + getItensDoPedido().size());
for (ItemDoPedido it : getItensDoPedido()) {
total += it.getQuantidade() * it.getValorUnitario();
Log.i("AULA", String.valueOf(total));
}
return total;
}
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
//Deseja excluir? = sim
getItensDoPedido().remove(position);
return true;
}
public void cancelar() {
itensDoPedido = null;
pedido = null;
finish();
}
public void gravar() {
PedidoDao pd = new PedidoDao();
pd.inserirPedido(getPedido());
PedidoItensDao pid = new PedidoItensDao();
for (ItemDoPedido it : getItensDoPedido()) {
it.setPedido(getPedido());
pid.inserirPedidoItens(it);
}
}
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
}
Client list screen code
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import br.gestaoBd.BancoDeDados.ClienteDao;
import br.gestaoBd.Beans.Cliente;
import br.gestaoBd.listaadapters.ClienteAdapter;
import java.util.ArrayList;
public class ListClientes extends Activity implements AdapterView.OnItemLongClickListener, AdapterView.OnItemClickListener {
ListView lista;
ArrayList<Cliente> clientes;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_clientes);
lista = (ListView) findViewById(R.id.listview);
lista.setOnItemLongClickListener(this);
lista.setOnItemClickListener(this);
atualizar(null);
}
public void atualizar(View view) {
ClienteDao cliDao = new ClienteDao();
clientes = cliDao.getListagem();
lista.setAdapter(new ClienteAdapter(getBaseContext(), clientes));
}
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Intent cadClienteIntent = new Intent(this, CadCliente.class);
cadClienteIntent.putExtra("Cliente", clientes.get(position));
startActivity(cadClienteIntent);
return true;
}
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent cadPedidoIntent = new Intent(this, CadPedido.class);
cadPedidoIntent.putExtra("Cliente", clientes.get(position));
startActivity(cadPedidoIntent);
}
}
I did exactly as you recommended and it’s still the same.. @Eudes
– Eduardo Krakhecke