I'm working on an advanced LayoutManager subclass. It has some special requirements in that it needs to manually add custom views, not associated with those generated by the adapter.
I have tried this example code...
public class TestLayoutManager extends RecyclerView.LayoutManager{
public TestLayoutManager(Context context){
TextView textView = new TextView(context);
textView.setLayoutParams(generateDefaultLayoutParams());
textView.setText("Hello World");
layoutDecorated(textView, 0, 0, 200, 100);
ignoreView(textView);
// When this line is called, it throws the error
this.addView(textView);
}
}
...but it throws an error in RecyclerView, here:
private void addViewInt(View child, int index, boolean disappearing) {
final ViewHolder holder = getChildViewHolderInt(child);
// Null-pointer exception here because 'holder' is null
if (disappearing || holder.isRemoved()) {
// these views will be hidden at the end of the layout pass.
mRecyclerView.mViewInfoStore.addToDisappearedInLayout(holder);
Somehow I need to associate a ViewHolder to the view without going through the adapter, but I'm not sure how to do that. Not sure it's possible, but if anyone knows, it'll be you guys here! :)
So... is it possible?