我有一个包含来自一个表的数据的列表视图,我需要在这种情况下显示:数据,值和名称,但列名在第二个表中。第一个表具有来自第二个表中的列名的id。因为我有一个Transacao数组,我不知道如何显示“名称”,因为它来自另一个类型(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()));