Android : SQLite show data from two tables listview

on Friday, July 4, 2014


I have a listview with data from one table, and i need to show in this case: data, value and name, but the column name is in a second table. The first table has a id from the column name that is in a second table. As i have an array of Transacao, i don't know how to show the "name" because it's from another Class type (Despesa).



public void Set_Refresh_Data() {
contact_data.clear();
db = new DatabaseHandler(this);
ArrayList<Transacao> contact_array_from_db = db.Get_transacao();

for (int i = 0; i < contact_array_from_db.size(); i++) {

int tidno = contact_array_from_db.get(i).getId();
String dia = contact_array_from_db.get(i).getDia();
String mes = contact_array_from_db.get(i).getMes();
String ano = contact_array_from_db.get(i).getAno();
int idFrom = contact_array_from_db.get(i).getIdFrom();
double valor = contact_array_from_db.get(i).getValor();

Transacao cnt = new Transacao();
cnt.setId(tidno);
cnt.setDia(dia);
cnt.setMes(mes);
cnt.setAno(ano);
cnt.setIdFrom(idFrom);
cnt.setValor(valor);

contact_data.add(cnt);
}
db.close();
cAdapter = new Contact_Adapter(Main_Screen.this, R.layout.listview_row,
contact_data);
Contact_listview.setAdapter(cAdapter);
cAdapter.notifyDataSetChanged();
}




public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
UserHolder holder = null;

if (row == null) {
LayoutInflater inflater = LayoutInflater.from(activity);

row = inflater.inflate(layoutResourceId, parent, false);
holder = new UserHolder();
holder.data = (TextView) row.findViewById(R.id.user_name_txt);
holder.valor = (TextView) row.findViewById(R.id.user_email_txt);
holder.idFrom = (TextView) row.findViewById(R.id.user_mob_txt);
holder.edit = (Button) row.findViewById(R.id.btn_update);
holder.delete = (Button) row.findViewById(R.id.btn_delete);
row.setTag(holder);
} else {
holder = (UserHolder) row.getTag();
}
user = data.get(position);
holder.edit.setTag(user.getId());
holder.delete.setTag(user.getId());
holder.data.setText(user.getDia() + "/" + user.getMes() + "/"
+ user.getAno());
holder.valor.setText("R$ " + String.valueOf(user.getValor()));
holder.idFrom.setText(String.valueOf(user.getIdFrom()));

0 comments:

Post a Comment