Estoy intentado cargar un listado pero cada vez que intento actualizar la vista del recyclerview, no me carga los datos, sólo carga el primer registro, aquí os dejo el código:
public class LoadInfo extends AsyncTask<Void, People, Void> {
private RecyclerView recyclerView;
private ProgressBar progressBar;
private Context context;
private PeopleAdapter peopleAdapter;
public LoadInfo(RecyclerView recyclerView,ProgressBar progressBar, Context context){
this.recyclerView = recyclerView;
this.context = context;
this.progressBar = progressBar;
}
@Override
protected void onPreExecute() {
peopleAdapter = new PeopleAdapter();
recyclerView.setAdapter(peopleAdapter);
progressBar.setVisibility(View.VISIBLE);
}
@Override
protected Void doInBackground(Void... voids) {
InputStream flujo = null;
try
{
flujo = context.getResources().openRawResource(R.raw.nombres);
BufferedReader lector = new BufferedReader(new InputStreamReader(flujo));
String texto = lector.readLine();
while(texto != null)
{
publishProgress(new People(texto));
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
texto = lector.readLine();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
if (flujo != null)
{
flujo.close();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
return null;
}
@Override
protected void onProgressUpdate(People... values) {
peopleAdapter.updateList(values[0]);
}
@Override
protected void onPostExecute(Void aVoid) {
progressBar.setVisibility(View.GONE);
}
}
public class PeopleAdapter extends RecyclerView.Adapter<PeopleViewHolder> {
private ArrayList<People> peopleList;
public PeopleAdapter() {
this.peopleList = new ArrayList<>();
}
@Override
public PeopleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_list, parent, false);
return new PeopleViewHolder(itemView);
}
@Override
public void onBindViewHolder(PeopleViewHolder holder, int position) {
holder.getName().setText(peopleList.get(position).getName());
holder.getCount().setText(String.valueOf(peopleList.get(position).getCount()));
}
@Override
public int getItemCount() {
return peopleList.size();
}
public void updateList(People person){
peopleList.add(person);
notifyDataSetChanged();
}
}
Gracias de antemano!