A little late, but I found a way to make it work.
My recyclerview contains a large number of viewers, and only one of the viewers has a progress bar. I have a sqlite database in which I maintain identifiers that I use to synchronize between my service and activity (to determine which views in recyclerview need to be updated).
Depending on your implementation, you will need to find a way to determine which translation event matches that adapter element. I gave a simplified version of what I did below.
Model for the progress bar:
class ProgressModel{ String progressId; int progress = 0; } public int getProgress(){ return progress; }
ViewHolder:
public class ProgressViewHolder extends RecyclerView.ViewHolder { private ProgressBar mProgressBar; public ProgressViewHolder(View itemView) { mProgressBar = (ProgressBar) itemView.findViewById(R.id.mProgressBar); } public ProgressBar getProgressBar() { return mProgressBar; } }
In the recycliewiew adapter,
@Override public void onBindViewHolder(ProgressViewHolder holder, int position) { ProgressModel item = mData.get(position); int progress = item.getProgress(); if (progress > 0) { ProgressBar downloadProgress = holder.getProgressBar(); if (downloadProgress.isIndeterminate()) { downloadProgress.setIndeterminate(false); } downloadProgress.setProgress(progress); } } public void refresh(position, ProgressModel item){ mData.set(position, item); notifyItemChanged(position); }
In the Office, which implements the filling of the view, create a static instance of yourself and pass it to BroadcastReceiver. It took me a while to figure out that a static instance is required, otherwise the view will not be changed, although I call notifyItemchanged ().
public class MainActivity extends Activity{ private static MainActivity instance; private MyReceiver mReceiver; private MyAdapter mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); instance = this; mReceiver = new MyReceiver(instance);
Hope this helps.
mUser1990
source share