gpt4 book ai didi

java - android listview setOnScrollListener 不工作

转载 作者:太空宇宙 更新时间:2023-11-04 13:12:31 31 4
gpt4 key购买 nike

我正在工作 BaseAdapter.i 有自定义 ArrayList.i 成功地在我的 ListView 中调整了我的自定义 ListView 这是我的基本适配器源

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 方法有什么问题?如果有人知道解决方案请帮助我谢谢大家

最佳答案

将您的滚动监听器更新为:

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) {
}

});

关于java - android listview setOnScrollListener 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33822347/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com