I'm developing an android app and am facing the following problem, I created an Adapter to populate my ListView but only fills in the header and is not getting into the getView () method to populate the items in my list, / p>
XML where the ListView contains
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:descendantFocusability="blocksDescendants">
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="br.com.gerenciarsc.nfce.view.PagamentoActivity">
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/btn_adicionarpgto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:onClick="adicionaPagamento"
android:gravity="center"
android:text="@string/btnaddpagto"
bootstrap:bootstrapBrand="success"
bootstrap:bootstrapSize="lg"
bootstrap:roundedCorners="true" />
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<ListView
android:id="@+id/list_view_pagamento"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Button Code where I call the Adapter that should populate my listview
final LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.list_item_pagamento, listView, false);
listView.addHeaderView(rowView);
if (listaPagamentos.size() > 0 && listaPagamentos != null)
listView.setAdapter(new ListaArrayPagamento(this, R.layout.list_item_pagamento, listaPagamentos, pgtoRepo));
My Adapter class
public class ListaArrayPagamento extends ArrayAdapter<String> {
private LayoutInflater inflater;
private List lista;
private PagamentoRepositorio pgtoRepo;
@SuppressWarnings("unchecked")
public ListaArrayPagamento(Context context, int recurso, List objetos, PagamentoRepositorio pgtoRepo) {
super(context, recurso, objetos);
this.pgtoRepo = pgtoRepo;
this.lista = objetos;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//position = position - 1;
if (convertView == null)
convertView = inflater.inflate(R.layout.list_item_pagamento, parent, false);
if (lista.get(position).getClass().isInstance(new PagamentoVenda())) {
final PagamentoVenda pagamentoVenda = (PagamentoVenda) lista.get(position);
try {
pgtoRepo.Atualizar(pagamentoVenda);
} catch (Exception e) {
e.printStackTrace();
}
((TextView) convertView.findViewById(R.id.tv_formapgto)).setText(pagamentoVenda.formaPagamento);
((TextView) convertView.findViewById(R.id.tv_valor)).setText(String.valueOf(pagamentoVenda.valorParcela));
if (pagamentoVenda.dtVencimento != null)
((TextView) convertView.findViewById(R.id.tv_dtvencimento)).setText(MainActivity.converteDataParaString(pagamentoVenda.dtVencimento, getContext().getResources().getString(R.string.data_formato)));
else
((TextView) convertView.findViewById(R.id.tv_dtvencimento)).setText("À vista");
}
return convertView;
}
}