Ir para o conteúdo
  • Revista PROGRAMAR: Já está disponível a edição #59 da revista programar. Faz já o download aqui!

rodrigolfm

Ajuda

Mensagens Recomendadas

rodrigolfm    0
rodrigolfm

Olá! Boa Tarde! Eu já tentei usando convertView direto, sem o ViewHolder e tenho o mesmo resultado. Ao 'scrollar' estou perdendo os valores. As positions ficam se perdendo,

Há algum erro nesta implementação?

Este projeto foi desenhado desta forma:

RelativeLayout

- LinearLayout

- ListView

- Item da List

No onclick aparece e somem textviews de acordo com um requisito interno.

public class AccountStatementArrayAdapter extends ArrayAdapter<ListaExtratos> {

private List<ListaExtratos> accountStatementList;

private String datas = "";

public AccountStatementArrayAdapter(Context context, int textViewResourceId, List<ListaExtratos> listaExtratoses) {

super(context, textViewResourceId, listaExtratoses);

accountStatementList = listaExtratoses;

}

@Override

public int getCount() {

return accountStatementList.size();

}

@Override

public ListaExtratos getItem(int position) {

return accountStatementList.get(position);

}

private static class ViewHolder {

TextView simpleDescriptionTextView,

txtDataExtrato,

simpleValueTextView,

completeDescriptionTextView,

completeDateTextView,

completeValueTextView,

completeDocumentTextView,

completeBalanceTextView;

}

public View getView(int position, View convertView, ViewGroup parent) {

ListaExtratos item = accountStatementList.get(position);

View rowView = convertView;

ViewHolder viewHolder;

if (rowView == null) {

LayoutInflater inflater = LayoutInflater.from(getContext());

rowView = inflater.inflate(R.layout.list_item_account_statement, parent, false);

viewHolder = new ViewHolder();

viewHolder.simpleDescriptionTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_simple_description_field);

viewHolder.txtDataExtrato = (TextView) rowView.findViewById(R.id.txtDataExtrato);

viewHolder.simpleValueTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_simple_value_field);

viewHolder.completeDescriptionTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_complete_description_field);

viewHolder.completeDateTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_complete_date_field);

viewHolder.completeValueTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_complete_value_field);

viewHolder.completeDocumentTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_complete_document_field);

viewHolder.completeBalanceTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_complete_balance_field);

rowView.setTag(viewHolder);

}else{

viewHolder = (ViewHolder) rowView.getTag();

}

if(item.getHistorico() != null) {

viewHolder.simpleDescriptionTextView.setText(item.getHistorico());

}else{

viewHolder.simpleDescriptionTextView.setText("");

}

if ((item.getValor() != null) && (Double.parseDouble(item.getValor()) < 0)) {

viewHolder.simpleValueTextView.setTextColor(Color.RED);

viewHolder.completeValueTextView.setTextColor(Color.RED);

viewHolder.completeValueTextView.setText(StringUtil.getStringValueFromBigDecimal(new BigDecimal(item.getValor())));

viewHolder.simpleValueTextView.setText(StringUtil.getStringValueFromBigDecimal(new BigDecimal(item.getValor())));

} else {

viewHolder.simpleValueTextView.setTextColor(Color.BLACK);

viewHolder.completeValueTextView.setTextColor(Color.BLACK);

viewHolder.completeValueTextView.setText(StringUtil.getStringValueFromBigDecimal(new BigDecimal(item.getValor())));

viewHolder.simpleValueTextView.setText(StringUtil.getStringValueFromBigDecimal(new BigDecimal(item.getValor())));

}

viewHolder.completeDescriptionTextView.setText(item.getHistorico());

viewHolder.completeDateTextView.setText(item.getData());

viewHolder.completeDocumentTextView.setText(item.getDocto());

viewHolder.completeBalanceTextView.setVisibility(View.GONE);

if (!datas.contains(item.getData())) {

viewHolder.txtDataExtrato.setVisibility(View.VISIBLE);

viewHolder.txtDataExtrato.setText(DateUtil.getDataPorExtenso(DateUtil.dateFromString(item.getData(), "dd/MM/yyyy")));

datas += item.getData() + ";";

} else {

viewHolder.txtDataExtrato.setVisibility(View.GONE);

}

return rowView;

}

}

public class AccountStatementArrayAdapter extends ArrayAdapter<ListaExtratos> {

private List<ListaExtratos> accountStatementList;

private String datas = "";

public AccountStatementArrayAdapter(Context context, int textViewResourceId, List<ListaExtratos> listaExtratoses) {

super(context, textViewResourceId, listaExtratoses);

accountStatementList = listaExtratoses;

}

@Override

public int getCount() {

return accountStatementList.size();

}

@Override

public ListaExtratos getItem(int position) {

return accountStatementList.get(position);

}

private static class ViewHolder {

TextView simpleDescriptionTextView,

txtDataExtrato,

simpleValueTextView,

completeDescriptionTextView,

completeDateTextView,

completeValueTextView,

completeDocumentTextView,

completeBalanceTextView;

}

public View getView(int position, View convertView, ViewGroup parent) {

ListaExtratos item = accountStatementList.get(position);

View rowView = convertView;

ViewHolder viewHolder;

if (rowView == null) {

LayoutInflater inflater = LayoutInflater.from(getContext());

rowView = inflater.inflate(R.layout.list_item_account_statement, parent, false);

viewHolder = new ViewHolder();

viewHolder.simpleDescriptionTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_simple_description_field);

viewHolder.txtDataExtrato = (TextView) rowView.findViewById(R.id.txtDataExtrato);

viewHolder.simpleValueTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_simple_value_field);

viewHolder.completeDescriptionTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_complete_description_field);

viewHolder.completeDateTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_complete_date_field);

viewHolder.completeValueTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_complete_value_field);

viewHolder.completeDocumentTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_complete_document_field);

viewHolder.completeBalanceTextView = (TextView) rowView.findViewById(R.id.list_item_account_statement_complete_balance_field);

rowView.setTag(viewHolder);

}else{

viewHolder = (ViewHolder) rowView.getTag();

}

if(item.getHistorico() != null) {

viewHolder.simpleDescriptionTextView.setText(item.getHistorico());

}else{

viewHolder.simpleDescriptionTextView.setText("");

}

if ((item.getValor() != null) && (Double.parseDouble(item.getValor()) < 0)) {

viewHolder.simpleValueTextView.setTextColor(Color.RED);

viewHolder.completeValueTextView.setTextColor(Color.RED);

viewHolder.completeValueTextView.setText(StringUtil.getStringValueFromBigDecimal(new BigDecimal(item.getValor())));

viewHolder.simpleValueTextView.setText(StringUtil.getStringValueFromBigDecimal(new BigDecimal(item.getValor())));

} else {

viewHolder.simpleValueTextView.setTextColor(Color.BLACK);

viewHolder.completeValueTextView.setTextColor(Color.BLACK);

viewHolder.completeValueTextView.setText(StringUtil.getStringValueFromBigDecimal(new BigDecimal(item.getValor())));

viewHolder.simpleValueTextView.setText(StringUtil.getStringValueFromBigDecimal(new BigDecimal(item.getValor())));

}

viewHolder.completeDescriptionTextView.setText(item.getHistorico());

viewHolder.completeDateTextView.setText(item.getData());

viewHolder.completeDocumentTextView.setText(item.getDocto());

viewHolder.completeBalanceTextView.setVisibility(View.GONE);

if (!datas.contains(item.getData())) {

viewHolder.txtDataExtrato.setVisibility(View.VISIBLE);

viewHolder.txtDataExtrato.setText(DateUtil.getDataPorExtenso(DateUtil.dateFromString(item.getData(), "dd/MM/yyyy")));

datas += item.getData() + ";";

} else {

viewHolder.txtDataExtrato.setVisibility(View.GONE);

}

return rowView;

}

}

Partilhar esta mensagem


Ligação para a mensagem
Partilhar noutros sites

Crie uma conta ou ligue-se para comentar

Só membros podem comentar

Criar nova conta

Registe para ter uma conta na nossa comunidade. É fácil!

Registar nova conta

Entra

Já tem conta? Inicie sessão aqui.

Entrar Agora

×

Aviso Sobre Cookies

Ao usar este site você aceita os nossos Termos de Uso e Política de Privacidade. Este site usa cookies para disponibilizar funcionalidades personalizadas. Para mais informações visite esta página.