我目前正在使用Android和UltimateRecycleView。我设法使ultimaterecycleview工作,但是当我尝试使用加载更多功能时,底部进度条没有显示(尽管数据已加载)。有谁遇到过这个问题?你能帮我找出问题吗?
以下是代码:
---适配器---
public class ListPendingAdapter extends UltimateViewAdapter<ListPendingAdapter.PendingViewHolder> {
private Context context;
private List<Queue> queues;
public ListPendingAdapter(Context context, List<Queue> queues) {
this.context = context;
this.queues = queues;
}
@Override
public PendingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.pending_list, parent, false);
PendingViewHolder vh = new PendingViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(PendingViewHolder holder, int position) {
TextView nodata = (TextView) ((Activity) context).findViewById(R.id.nodata);
if(queues.size() <= 0){
nodata.setVisibility(View.VISIBLE);
} else {
nodata.setVisibility(View.GONE);
User user = new User(queues.get(position).getQueuer());
if (user.getProfilePicture() == null) {
holder.photo.setImageDrawable(context.getResources().getDrawable(R.drawable.default_photo));
} else {
ImageUtil.setParseFileImageToView(context, user.getProfilePicture(), holder.photo);
}
holder.name.setText(user.getFullname());
holder.totalPerson.setText(Integer.toString(queues.get(position).getTotalPax()));
holder.timeQueue.setText(DateUtil.formatDateIntoTimeString(queues.get(position).getCreatedAt()));
attachButtonClickListener(holder.accept, true, position, holder.parent);
attachButtonClickListener(holder.reject, false, position, holder.parent);
CustomerUtil.attachUsernameListener((Activity) context, holder.name, queues.get(position));
CustomerUtil.attachProfpicListener((Activity) context, holder.photo, queues.get(position));
}
}
@Override
public int getItemCount() {
int size = (queues == null ? 0 : queues.size());
return size;
}
@Override
public PendingViewHolder onCreateViewHolder(ViewGroup viewGroup) {
View v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.pending_list, viewGroup, false);
PendingViewHolder vh = new PendingViewHolder(v);
return vh;
}
@Override
public PendingViewHolder getViewHolder(View view) {
return new PendingViewHolder(view);
}
@Override
public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup viewGroup) {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.custom_bottom_progressbar, viewGroup, false);
return new RecyclerView.ViewHolder(view) {
};
}
@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
}
@Override
public long generateHeaderId(int position) {
if (getItem(position).get("objectId").toString().length() > 0)
return (getItem(position).get("objectId").toString()).charAt(0);
else return -1;
}
@Override
public int getAdapterItemCount() {
int size = (queues == null ? 0 : queues.size());
return size;
}
public Queue getItem(int position) {
if (customHeaderView != null)
position--;
if (position < queues.size())
return queues.get(position);
else return null;
}
private void attachButtonClickListener(Button button, final boolean isAccept, final int position, final View parent){
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
callPendingProcess(isAccept, position, parent);
}
});
}
private void callPendingProcess(final boolean isAccept, final int position, final View parent){
ProcessPending processPending = new ProcessPending(context, this, isAccept, position, parent);
processPending.execute();
}
public List<Queue> getDataset(){
return queues;
}
public static class PendingViewHolder extends UltimateRecyclerviewViewHolder {
public CircleImageView photo;
public TextView name;
public TextView totalPerson;
public TextView timeQueue;
public Button accept;
public Button reject;
public View parent;
public PendingViewHolder(View v) {
super(v);
parent = v;
photo = (CircleImageView) v.findViewById(R.id.photo);
name = (TextView) v.findViewById(R.id.cust_name);
totalPerson = (TextView) v.findViewById(R.id.total_cust);
timeQueue = (TextView) v.findViewById(R.id.time_queue);
accept = (Button) v.findViewById(R.id.accept_btn);
reject = (Button) v.findViewById(R.id.reject_btn);
}
}
}
---异步任务(我将适配器设置为listview)---
public class LoadPendingCustomer extends AsyncTask<Void, Void, List<Queue>> {
private Context context;
private Activity activity;
private ProgressBar pb;
private View view;
private View layout;
private int skipCount;
private boolean isLoadMore;
public LoadPendingCustomer(Context context, View layout, int skipCount, boolean isLoadMore) {
this.context = context;
this.activity = (Activity) context;
this.layout = layout;
this.skipCount = skipCount;
this.isLoadMore = isLoadMore;
this.pb = (ProgressBar) layout.findViewById(R.id.pending_progress);
this.view = layout.findViewById(R.id.pending_list_container);
}
@Override
protected void onPreExecute() {
if(!isLoadMore) {
ProgressUtil.showProgress(true, view, pb, context);
}
}
@Override
protected List<Queue> doInBackground(Void... arg0) {
List<Queue> queues = null;
try {
List<String> statuses = new ArrayList<String>();
statuses.add(Queue.STATUS_PENDING_APPROVAL);
queues = QueueDao.getCustomersBasedOnStatus(statuses, skipCount);
} catch (ParseException e) {
Log.w(MainActivity.TAG, "Error while retrieving pending queues", e);
}
return queues;
}
@Override
protected void onPostExecute(List<Queue> results) {
TextView nodata = (TextView) layout.findViewById(R.id.nodata);
if(results == null){
nodata.setVisibility(View.VISIBLE);
} else {
if (results.size() <= 0) {
if(!isLoadMore) {
nodata.setVisibility(View.VISIBLE);
}
} else {
nodata.setVisibility(View.GONE);
UltimateRecyclerView queueList = (UltimateRecyclerView) layout.findViewById(R.id.pendinglist);
if(!isLoadMore || queueList.getAdapter() == null){
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(activity);
ListPendingAdapter listPendingAdapter = new ListPendingAdapter(context, results);
queueList.setLayoutManager(layoutManager);
queueList.setAdapter(listPendingAdapter);
} else {
ListPendingAdapter listPendingAdapter = (ListPendingAdapter) queueList.getAdapter();
listPendingAdapter.getDataset().addAll(results);
listPendingAdapter.notifyDataSetChanged();
}
setLoadMore(queueList);
}
}
if(!isLoadMore) {
ProgressUtil.showProgress(false, view, pb, context);
}
}
private void setLoadMore(final UltimateRecyclerView queueList){
queueList.reenableLoadmore();
queueList.setLoadMoreView(R.layout.custom_bottom_progressbar);
queueList.setOnLoadMoreListener(new UltimateRecyclerView.OnLoadMoreListener() {
@Override
public void loadMore(int i, int i1) {
LoadPendingCustomer loadPendingCustomer = new LoadPendingCustomer(context, layout, skipCount + 10, true);
loadPendingCustomer.execute();
}
});
}
}
---片段xml ---
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
tools:context=".fragments.QueueFragment">
<!-- TODO: Update blank fragment layout -->
<ProgressBar
android:id="@+id/pending_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:visibility="gone" />
<LinearLayout
android:id="@+id/pending_list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/nodata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/nodata"
android:visibility="gone"/>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/pending_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.marshalchen.ultimaterecyclerview.UltimateRecyclerView
android:id="@+id/pendinglist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"/>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</RelativeLayout>
--- custom_bottom_progressbar.xml ---
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottomPB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffff">
<ProgressBar
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/bottom_progress_bar"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/loading"
android:layout_below="@+id/bottom_progress_bar"
android:layout_marginTop="2dp"
android:gravity="center"/>
</RelativeLayout>
请帮帮我。提前谢谢......