gpt4 book ai didi

android - 图书 list 项目。每本书搜索都与以前的结果重叠。你如何清除ListView?

转载 作者:行者123 更新时间:2023-11-29 19:07:16 29 4
gpt4 key购买 nike

这是我的点击信息:

        Button searchButton = (Button) findViewById(R.id.search_button);
searchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

BookListFragment bookListFragment = new BookListFragment();

getSupportFragmentManager().beginTransaction()
.add(R.id.book_list_frame, bookListFragment).commit();

}

});

带有 BookLoader 的 BookListFragment:

    @Override
public Loader<List<BookListing>> onCreateLoader(int i, Bundle args) {

return new BookLoader(this, GOOGLE_BOOKS_URL + searchedBook);
}


@Override
public void onLoadFinished(Loader<List<BookListing>> loader, List<BookListing> bookListings) {
mAdapter.clear();


if(bookListings != null && !bookListings.isEmpty()) {
mAdapter.addAll(bookListings);
}

}

@Override
public void onLoaderReset(Loader<List<BookListing>> loader) {
mAdapter.clear();

}

我能够得到搜索结果。但是当再次搜索时,以前的结果并不清楚。它们只是不断重叠。

First Search Screenshot Second Search Screenshot

最佳答案

 @Override
public Loader<List<BookListing>> onCreateLoader(int i, Bundle args) {

return new BookLoader(this, GOOGLE_BOOKS_URL + searchedBook);
}


@Override
public void onLoadFinished(Loader<List<BookListing>> loader,
List<BookListing> bookListings) {
mAdapter.clear();


if(bookListings != null && !bookListings.isEmpty()) {
mAdapter.replace(bookListings);
}

}
@Override
public void onLoaderReset(Loader<List<BookListing>> loader) {
mAdapter.clear();
}

关于android - 图书 list 项目。每本书搜索都与以前的结果重叠。你如何清除ListView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46715107/

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