In my BaseExpandableListAdaptar i have List of class AdaptorData. This AdaptorData consists of Date and Object of Payment class. I am getting Payment object for every date in my adaptor. i.e. 25 mar - payment 1 25 mar - payment 2,26 mar payment 3, 26 mar payment 4,26 mar payment 5 etc. In my get group view method i have added logic like if payment data coming from same date then it should come under only that date. All works perfectly, Only when i scroll up my data gets scattered, That is 26 mar records will go under 25 march.
Here is my code-
Adapter-
public class PaymentAdapter extends BaseExpandableListAdapter implemen Filterable {
private LayoutInflater inflater;
private BaseActivity context;
private List<AdaptorData> dataAdaptor;
public String currentDate;
private List<AdaptorData> mStringFilterList;
ValueFilter valueFilter;
private String dateObj;
private ValueFilter mFilter = new ValueFilter();
public PaymentAdapter(final BaseActivity context, final List<AdaptorData> dataAdaptor) {
this.context = context;
this.dataAdaptor = dataAdaptor;
this.mStringFilterList = dataAdaptor;
inflater = LayoutInflater.from(context);
}
@Override
public int getGroupCount() {
return dataAdaptor.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return 1;
}
@Override
public Object getGroup(int groupPosition) {
return dataAdaptor.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return 1;
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, final View convertView, ViewGroup parent) {
ViewHolder holder;
View adapterView = null;
// if (convertView == null) {
adapterView = inflater.inflate(R.layout.row_upcoming_or_recurring, parent, false);
holder = new ViewHolder();
adapterView.setTag(holder);
// } else {
// adapterView = convertView;
// holder = (ViewHolder)adapterView.getTag();
// }
holder.textdate = (TextView)adapterView.findViewById(R.id.date_transaction);
holder.paymentView = (RelativeLayout)adapterView.findViewById(R.id.payment_info_layout);
holder.paymentTypeIndicator = (View)adapterView.findViewById(R.id.payment_type_indicator);
holder.paymentName = (TextView)adapterView.findViewById(R.id.payment_name);
holder.fromAccount = (TextView)adapterView.findViewById(R.id.from_account);
holder.transactionAmountText = (TextView)adapterView.findViewById(R.id.payment_amount);
holder.paymentTypeTextview = (TextView)adapterView.findViewById(R.id.recurring_or_upcoming);
holder.textdate.setVisibility(View.GONE);
holder.textdate.setClickable(false);
if (currentDate != dataAdaptor.get(groupPosition).getDate()) {
holder.textdate.setVisibility(View.VISIBLE);
dateObj = DateTimeUtils.convertUnixTimeStampDate(Long.parseLong(dataAdaptor.get(groupPosition).getDate()), DateTimeUtils.DATE_FORMAT_SWEDISH);
holder.textdate.setText(dateObj);
currentDate = dataAdaptor.get(groupPosition).getDate();
} else {
holder.textdate.setVisibility(View.GONE);
}
holder.paymentView.setBackgroundColor(context.getResources().getColor(R.color.listitem_default));
Details paymentInfo = dataAdaptor.get(groupPosition).getPayments().getDetails();
int typeColor = R.color.economic_view_red;
holder.paymentTypeIndicator.setBackgroundColor(context.getResources().getColor(typeColor));
UiUtils.setPayerInfoText(context, holder.paymentName, dataAdaptor.get(groupPosition).getPayments());
holder.paymentName.setTypeface(FontUtils.getFuturaHeavy());
holder.fromAccount.setText(context.getString(R.string.PAYMNET_AND_TRANSFER_FROM_TEXT) + WebUtils.COLOM_STRING
+ FactoryUtils.getAccountNickName(context, dataAdaptor.get(groupPosition).getPayments().getThisAccount(), true, null));
holder.fromAccount.setTypeface(FontUtils.getFuturaHeavy());
holder.transactionAmountText.setTypeface(FontUtils.getFuturaHeavy());
MonetaryAmount monetaryAmt = paymentInfo.getValue();
String amount = monetaryAmt.getAmountValue().toString();
holder.transactionAmountText.setText(UiUtils.getFormatedCurreancy(amount, context.getResources()));
holder.paymentTypeTextview.setTextColor(context.getResources().getColor(typeColor));
holder.paymentTypeTextview.setTypeface(FontUtils.getFuturaHeavy());
holder.paymentTypeTextview.setText("Bank Transfer to another account");
if (UiUtils.isEInvoiceActive(dataAdaptor.get(groupPosition).getPayments())) {
holder.paymentEnvoice = (TextView)convertView.findViewById(R.id.payment_envoice);
holder.paymentEnvoice.setTypeface(FontUtils.getFuturaHeavy());
holder.paymentEnvoice.setVisibility(View.VISIBLE);
holder.paymentEnvoice.setText("E-invoice");
}
return adapterView;
}
static class ViewHolder {
TextView textdate;
RelativeLayout paymentView;
View paymentTypeIndicator;
TextView paymentName;
TextView fromAccount;
TextView transactionAmountText;
TextView paymentTypeTextview;
TextView paymentEnvoice;
}
static class ViewchildHolder {
TextView toView;
TextView toValue;
TextView balanceView;
TextView balanceValue;
TextView fromView;
TextView fromValue;
TextView dateView;
TextView dateValue;
TextView msgView;
TextView msgValue;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View detailsLayout, ViewGroup parent) {
ViewchildHolder holder;
View row = null;
// if (detailsLayout == null) {
row = (LinearLayout)inflater.inflate(R.layout.payment_details, parent, false);
holder = new ViewchildHolder();
row.setTag(detailsLayout);
// } else {`enter code here`
// row = detailsLayout;
// holder = (ViewchildHolder)row.getTag();
// }
holder.toValue = (TextView)row.findViewById(R.id.paymt_to_value);
holder.balanceView = (TextView)row.findViewById(R.id.paymt_sum_view);
holder.balanceValue = (TextView)row.findViewById(R.id.paymt_sum_value);
holder.fromView = (TextView)row.findViewById(R.id.paymt_from_view);
holder.fromValue = (TextView)row.findViewById(R.id.paymt_from_value);
holder.dateView = (TextView)row.findViewById(R.id.paymt_date_view);
holder.dateValue = (TextView)row.findViewById(R.id.paymt_date_value);
holder.msgView = (TextView)row.findViewById(R.id.paymt_ocr_msg_view);
holder.msgValue = (TextView)row.findViewById(R.id.paymt_ocr_msg_value);
row.setBackgroundColor(context.getResources().getColor(R.color.listitem_detail_list));
Details detail = dataAdaptor.get(groupPosition).getPayments().getDetails();
holder.toView = (TextView)row.findViewById(R.id.paymt_to_view);
holder.toView.setTypeface(FontUtils.getFuturaBook());
Account toAccount = dataAdaptor.get(groupPosition).getPayments().getOtherAccount();
holder.toValue.setTypeface(FontUtils.getFuturaHeavy());
holder.toValue.setText(FactoryUtils.getAccountNickName(context, toAccount, false, detail.getDetailsType()));
holder.balanceView.setTypeface(FontUtils.getFuturaBook());
holder.balanceValue.setText(UiUtils.getFormatedCurreancy(detail.getValue().getAmountValue(), context.getResources()));
holder.balanceValue.setTypeface(FontUtils.getFuturaHeavy());
holder.balanceValue.setText(UiUtils.getFormatedCurreancy(detail.getValue().getAmountValue(), context.getResources()));
Account fromAccount = dataAdaptor.get(groupPosition).getPayments().getThisAccount();
holder.fromView.setTypeface(FontUtils.getFuturaBook());
holder.fromValue.setTypeface(FontUtils.getFuturaHeavy());
holder.fromValue.setText(FactoryUtils.getAccountNickName(context, fromAccount, false, null));
holder.dateView.setTypeface(FontUtils.getFuturaBook());
holder.dateValue.setTypeface(FontUtils.getFuturaHeavy());
List<Action> actionList = detail.getActionsList();
String strDate = actionList.get(0).getDate();
String dateObj = DateTimeUtils.convertUnixTimeStampDate(Long.parseLong(strDate), DateTimeUtils.GENERAL_DATE_FORMAT);
holder.dateValue.setText(dateObj);
holder.msgView.setTypeface(FontUtils.getFuturaBook());
holder.msgValue.setTypeface(FontUtils.getFuturaHeavy());
if (detail.getMessage() != null) {
holder.msgValue.setText(detail.getMessage());
TransactionUtils.setMaxLine(detail.getMessage(), holder.msgValue);
} else if (UiUtils.getLoginMethodType() == LoginMethodType.LOGIN_DEMO) {
holder.msgValue.setText("Help");
}`enter code here`
return detailsLayout;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
I have tried all ways mentioned [here] (Android - Expandable ListView - using ViewHolder for optimization)! and [here] How ListView's recycling mechanism works)!
Also, I have tried setTag for view and get tag for that view. that code is commented in code. But nothing is working for me.
Can any one help me on this? Please let me know if you want more info.