在我的BaseExpandableListAdaptar中,我有类AdaptorData的列表。 此AdaptorData由Date和Object of Payment类组成。 我正在获取适配器中每个日期的Payment对象。即25月3日 - 付款1 3月25日 - 支付2,26 3月3日支付3月26日支付4,26 3月支付5等 在我的获取组视图方法中,我添加了逻辑,如果支付数据来自同一日期,那么它应该仅在该日期之前。 一切都很完美,只有当我向上滚动我的数据时才会分散,那就是26月3日的记录将会在25月3日之前完成。
这是我的代码 -
适配器 -
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;
}
}
我已经尝试了[这里](Android - Expandable ListView - using ViewHolder for optimization)提到的所有方法!和[这里] How ListView's recycling mechanism works)!
另外,我已尝试使用setTag进行查看并获取该视图的标记。 该代码在代码中被注释。 但没有什么对我有用。
任何人都能帮助我吗? 如果您想了解更多信息,请告诉我。