我正在使用BaseAdapter.i有自定义ArrayList.i成功地在我的listview中调整了我的自定义列表视图 这是我的baseadapter来源
public class TransactionAdapter extends BaseAdapter {
private Context context;
private List<Transaction> transactionList;
public TransactionAdapter(Context context, List<Transaction> values) {
this.context=context;
this.transactionList=values;
}
@Override
public int getCount() {
return transactionList.size();
}
@Override
public Object getItem(int position) {
return transactionList.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = LayoutInflater.from(context).inflate(R.layout.view_transaction_item, parent, false);
Transaction transaction = transactionList.get(position);
if (transaction != null) {
final TextView transactionName=(TextView)v.findViewById(R.id.u_transaction_name);
transaction.setAmount(transaction.getAmount().replace("-", ""));
transactionName.setText(transaction.getName());
((TextView) v.findViewById(R.id.u_transaction_status)).setText(transaction.getStatus());
((TextView) v.findViewById(R.id.u_transaction_ago)).setText(transaction.getPassedTime());
TextView date = (TextView) v.findViewById(R.id.u_transaction_date);
date.setText(UniPAYDateUtils.formatToDayMonthInWordAndYear(transaction.getDate()));
}
return v;
}
}
<ListView
android:id="@+id/u_dashboard_transactions_list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:divider="@null"
/>
现在我想编写setOnScrollListener方法,我想检查滚动的最后位置(如加载更多),但我无法检查最后位置 这是我的setOnScrollListener方法
customListview.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
currentScrollState = scrollState;
if (currentVisibleItemCount > 0 && currentScrollState == SCROLL_STATE_IDLE && totalItemCount == (currentFirstVisibleItem + currentVisibleItemCount)) {
if (!loadingMore) {
loadingMore = true;
Log.e("TAGGGGGGGGGGGGGGGGGGGGGGGGGGG","Visible Load More");
}
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
currentFirstVisibleItem = firstVisibleItem;
currentVisibleItemCount = visibleItemCount;
}
});
我的setOnScrollListener方法中有什么问题?如果有人知道解决方案,请帮助我 谢谢大家
答案 0 :(得分:0)
将您的滚动侦听器更新为:
customListview.setOnScrollListener(new AbsListView.OnScrollListener() {
private int visibleThreshold = 5;
private int currentPage = 0;
private int previousTotal = 0;
private boolean loading = true;
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
currentPage++;
}
}
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
// load more items
loading = true;
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
});