我正在使用recyclerview,在那个recyclerview中,我有cardview的列表。内容是静态的,不会改变。当我将列表拖到顶部时,将显示一个进度条并将其停留在此处。
如何解决该问题。我在互联网上进行搜索,但未找到相关内容。感谢您的回答!
来自仿真器的照片:https://i.imgur.com/2wIKwKk.png(注意进度条在中间加载)
RVAdapter.java
public class RVAdapter extends RecyclerView.Adapter<RVAdapter.PersonViewHolder> {
public static class PersonViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView personName;
TextView personAge;
ImageView personPhoto;
Button personbutton;
PersonViewHolder(View itemView) {
super(itemView);
cv = (CardView)itemView.findViewById(R.id.cv);
personName = (TextView)itemView.findViewById(R.id.person_name);
personAge = (TextView)itemView.findViewById(R.id.person_age);
personPhoto = (ImageView)itemView.findViewById(R.id.person_photo);
personbutton=(Button)itemView.findViewById(R.id.imgbuttondownload);
}
}
List<Person> persons;
RVAdapter(List<Person> persons){
this.persons = persons;
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
@Override
public PersonViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, viewGroup, false);
PersonViewHolder pvh = new PersonViewHolder(v);
return pvh;
}
@Override
public void onBindViewHolder(PersonViewHolder personViewHolder, final int i) {
personViewHolder.personName.setText(persons.get(i).name);
personViewHolder.personAge.setText(persons.get(i).age);
personViewHolder.personPhoto.setImageResource(persons.get(i).photoId);
personViewHolder.personPhoto.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Context context=v.getContext();
Intent intent=new Intent();
switch (i){
case 0:
intent = new Intent(context, Main4Activity.class);
context.startActivity(intent);
break;
case 1:
intent = new Intent(context, Main4Activity.class);
context.startActivity(intent);
break;
case 2:
intent = new Intent(context, Main4Activity.class);
context.startActivity(intent);
break;
case 3:
intent = new Intent(context, Main4Activity.class);
context.startActivity(intent);
break;
}
}
});
personViewHolder.personbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Person person = persons.get(i);
Context context=v.getContext();
String url = person.url;
DownloadManager manager = (DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription(person.title);
request.setTitle(person.title);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "file"+person.title+".mp4");
manager.enqueue(request);
}
});
}
@Override
public int getItemCount() {
return persons.size();
}
}
MainActivity.java
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
rv=(RecyclerView)findViewById(R.id.rv);
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE
}, REQUEST_CODE);
LinearLayoutManager llm = new LinearLayoutManager(this);
rv.setLayoutManager(llm);
rv.setHasFixedSize(true);
initializeData();
initializeAdapter();
}
private void initializeData(){
persons = new ArrayList<>();
persons.add(new Person("How to perform a staphylectomy | Surgical correction of RLN", "10:07", R.drawable.chirurgie,"https://drive.google.com/uc?export=download&id=1mxYNzdeCtp7mP5Jv0gqESTgIFa9pGhF1","YESddddd"));
persons.add(new Person("How to perfom a clinical examination", "07:03", R.drawable.chirurgie,"https://drive.google.com/uc?export=download&id=1mxYNzdeCtp7mP5Jv0gqESTgIFa9pGhF1","gvjhkllklkj2bb"));
persons.add(new Person("How to perform a radiographic examination", "03:50", R.drawable.chirurgie,"https://drive.google.com/uc?export=download&id=1mxYNzdeCtp7mP5Jv0gqESTgIFa9pGhF1","nadaaa"));
}
private void initializeAdapter(){
RVAdapter adapter = new RVAdapter(persons);
rv.setAdapter(adapter);
}
activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
tools:context=".MainActivity"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/app_bar_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/navigation_menu"
android:layout_gravity="right"
android:id="@+id/nv3"
android:background="@android:color/white"
app:headerLayout="@layout/navigation_header"
>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
App_bar_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:background="@color/redcolor"
android:layout_height="192dp"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimaryDark"
app:expandedTitleMarginStart="30dp"
app:expandedTitleMarginEnd="2dp"
app:collapsedTitleTextAppearance="@style/CollapsedAppBar"
app:expandedTitleTextAppearance="@style/ExpandedAppBar"
>
<ImageView
android:id="@+id/imagetoolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeToRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/rv"
>
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
答案 0 :(得分:2)
您有一个SwipeRefreshLayout。
通过findViewById
找到它,然后调用
swipeRefreshLayout.setRefreshing(false);
swipeRefreshLayout.setEnabled(false);