gpt4 book ai didi

java - 如果显示recyclerView,如何停止显示加载?

转载 作者:太空宇宙 更新时间:2023-11-04 09:25:40 26 4
gpt4 key购买 nike

如果显示回收器,我想停止显示进度条

 ProgressBar progressBar = findViewById(R.id.progressbar);
if (recyclerView.isShown()){
progressBar.setVisibility(View.GONE);
}
else {
progressBar.setVisibility(View.VISIBLE);
}

这是我在 android studio 中的 xml

<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/all_user_post_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/search_posts" />

我希望适配器位于主要 Activity 中,并且适配器将在主要 Activity 中显示,好吧,我猜就是这样

public class MainActivity extends AppCompatActivity {
EditText search;
String currentUserID;
private RecyclerView recyclerView;
private List<Posts> postList;
private AdapterPost adapterPost;

@Override
protected void onCreate(Bundle savedInstanceState) {
MultiDex.install(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

recyclerView = findViewById(R.id.all_user_post_list);

LinearLayoutManager layoutManager = new
LinearLayoutManager(MainActivity.this);
layoutManager.setStackFromEnd(true);
layoutManager.setReverseLayout(true);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
postList = new ArrayList<>();

LoadEveryUsersPosts();

最佳答案

试试这个代码:

    View recyclerview= (RecyclerView) findViewById(R.id.all_user_post_list);
recyclerview.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
progressBar.setVisibility(View.GONE);
recyclerview.getViewTreeObserver().removeOnGlobalLayoutListener(this);
//prevent infinite loop
}
});

关于java - 如果显示recyclerView,如何停止显示加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57742554/

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