Jump to content
rodrigolfm

Ajuda

Recommended Posts

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;

}

}

Share this post


Link to post
Share on other sites
Greemax

Recomendo que ponhas isso formatado em código (simbolo '<>' na toolbar) É mais fácil ajudar-te.

  • Vote 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.