2
I need a popular ListView
. I have a class that represents the Entity Cliete
,
a class that is responsible for the database database and finally a class ClienteDAO
, that the data of the entity remains Cliente
.
Follow the Classes:
Clientele
public class ClienteDAO {
private SQLiteDatabase DB;
protected Banco auxBanco;
private String TABELA = "CLIENTE";
public ClienteDAO(Context context)
{
Banco newBanco = new Banco(context);
DB = newBanco.getWritableDatabase();
//newBanco.onCreate(DB);
this.auxBanco = newBanco;
}
public ArrayList<Cliente> Listar_Clientes(){
ArrayList<Cliente> list = new ArrayList<Cliente>();
String[] colunas = new String[]{"_ID",
"NOME",
"APELIDO",
"OBSERVACAO",
"CELULAR",
"DATA_CADASTRO",
"DDD"};
Cursor Sn = DB.query(this.TABELA, colunas, null, null, null, null, "NOME ASC");
if(Sn.getCount() > 0){
Sn.moveToFirst();
do{
Cliente newCliente = new Cliente();
newCliente.set_ID(Sn.getLong(Sn.getColumnIndex("_ID")));
newCliente.setNome(Sn.getString(Sn.getColumnIndex("NOME")));
newCliente.setApelido(Sn.getString(Sn.getColumnIndex("APELIDO")));
newCliente.setCelular(Sn.getString(Sn.getColumnIndex("CELULAR")));
newCliente.setDDD(Sn.getString(Sn.getColumnIndex("DDD")));
newCliente.setObservacao(Sn.getString(Sn.getColumnIndex("OBSERVACAO")));
newCliente.setCelular(Sn.getString(Sn.getColumnIndex("DATA_CADASTRO")));
list.add(newCliente);
}while(Sn.moveToNext());
}
return(list);
}
Clienteadapter
public class ClienteAdapter extends BaseAdapter {
private Context context;
private ArrayList<Cliente> list;
public ClienteAdapter(Context context, ArrayList<Cliente> list){
this.context = context;
this.list = list;
}
@Override
public int getCount() {
list.size();
return 0;
}
@Override
public Object getItem(int position) {
list.get(position);
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Cliente cCliente = list.get(position);
View layout;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
layout = inflater.inflate(R.layout.itens_relacao_cliente, null);
}else
{
layout = convertView;
}
TextView Nome = (TextView) layout.findViewById(R.id.lblNome);
Nome.setText(cCliente.getNome());
TextView Apelido = (TextView) layout.findViewById(R.id.lblApelido);
Apelido.setText(cCliente.getApelido());
return layout;
}
}
Relacao_clients
public class Relacao_cliente extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_relacao_cliente);
try {
ClienteDAO BD = new ClienteDAO(this);
ArrayList<Cliente> Lista_Clientes = BD.Listar_Clientes();
ListView ListViewR_Cliente = (ListView) findViewById(R.id.lvRelacao_Cliente);
ListViewR_Cliente.setAdapter(new ClienteAdapter(this, Lista_Clientes));
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT);
}
}
}
What is your question? At first the code does what it should, according to your question.
– Wakim
The code doesn’t do what it’s supposed to. I would like to know if something is being done wrong, if any object needs to have a specific treatment before it is passed to another class. In this call I realized (debugging) that it does not enter the
public View getView
(Clienteadapter).ListViewR_Cliente.setAdapter(new ClienteAdapter(this, Lista_Clientes));
– Eduardo de Santana