java 默认情况下,包含progressbar项的base recyclerview适配器类。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 默认情况下,包含progressbar项的base recyclerview适配器类。相关的知识,希望对你有一定的参考价值。
package com.got2goto.android.components;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import com.got2goto.android.BaseApplication;
import java.util.ArrayList;
import java.util.List;
/**
* Abstract RecyclerView adapter class containing ProgressBar item and other helper functions.
*
* Created by Rafay Ali on 7/18/2016.
*/
public abstract class AbstractRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
public static final int ITEM_TYPE_PROGRESS_BAR = 0;
protected boolean isProgressBarVisible = false;
protected ProgressBar progressBar;
protected Context context;
protected List<Object> itemsList = new ArrayList<>();
public AbstractRecyclerViewAdapter(Context context){
this.context = context;
progressBar = new ProgressBar(this.context);
}
@Override
public int getItemViewType(int position) {
if (itemsList.get(position) instanceof ProgressBar)
return ITEM_TYPE_PROGRESS_BAR;
return -1;
}
@Override
public int getItemCount() {
return itemsList.size();
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType){
case ITEM_TYPE_PROGRESS_BAR:
View progressBarView = ((LayoutInflater) BaseApplication.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(getProgressBarLayoutResId(), parent, false);
return new ProgressBarViewHolder(progressBarView);
}
return null;
}
public void addItem(Object item){
itemsList.add(item);
}
public void addAllItems(List itemsList){
this.itemsList.addAll(itemsList);
}
public void removeItem(Object item){
itemsList.remove(item);
}
public void removeItemAtPosition(int position){
itemsList.remove(position);
}
public void removeAllItems(){
itemsList.clear();
}
public void showProgressBar(){
if (!isProgressBarVisible)
itemsList.add(progressBar);
isProgressBarVisible = true;
}
public void hideProgressBar(){
if (isProgressBarVisible)
itemsList.remove(progressBar);
isProgressBarVisible = false;
}
public abstract int getProgressBarLayoutResId();
}
以上是关于java 默认情况下,包含progressbar项的base recyclerview适配器类。的主要内容,如果未能解决你的问题,请参考以下文章
如何改变Android Progressbar默认颜色
如何改变Android Progressbar默认颜色
在没有调试器的情况下运行时,ProgressBar 会“卡住”
安装气流时出错:默认情况下,Airflow 的依赖项之一安装 GPL
在 Maven 中隐式包含可选依赖项
安卓ProgressBar水平进度条的颜色设置