Show a different viewType type in a RecyclerView based on information in a database?

Hit a little checkpoint and wonder how to solve it, it seems that a chicken and an egg for me can do with a fresh pair of eyes.

I have a database with information about places in them. I want to show all the places ordered by distance in mine RecyclerView.

I already dealt with this when only one viewType. However, this is something that I can’t understand, I want to show a different view for places located at a certain distance from the user. So, for example, within 100 meters.

This information is in my database, so when getItemViewType(int position)called in setAdapter (), mine CursorLoaderdid not finish pulling out all the information, so I get an exception with a null pointer.

On my question:

Is there a way to wait for my to CursorLoaderfinish working with my adapter and not be null Cursor? When I try to call .setAdapter()after the bootloader completes, I get the following in my logs: No adapter attached; skipping layoutbecause it RecyclerViewrequires the adapter to be installed when the action is created.

Now mine getItemViewType(position)looks like this:

if (!cursor.isClosed()) {
    cursor.moveToPosition(position);
}
if (cursor.getInt(2) <= 100) {
   return TYPE_NEARBY;
} else {
  return TYPE_NOT_NEARBY;
}

Essentially, I need to use the data in CursorLoaderto define viewTypeand load another view for this cell. This works with one ViewType, because I do not need to check the distance, they are all the same.

Thanks for any help you can offer!

+4
source share
1

blackbelts.

, , . , onBindViewHolder(int position).

, ViewHolder "holderId" int, viewType, , , .

0

All Articles