There is a BaseActivity with a layout and a sub Activity that extends this BaseActivity.
How do you bind views so that views in BaseActivity are binded in BaseActivity and views in Sub activity are binded there ?
Here is a sample code explaining the current scenario, Note: Sample code was taken from here
BASE ACTIVITY
public class BaseActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState, int layout) {
super.onCreate(savedInstanceState);
super.setContentView(layout);
ButterKnife.bind(this);
}
@Override
public void setContentView(int layoutResID) {
//I added my own implementation here
}
}
SUB ACTIVITY
public class SplashActivity extends BaseActivity {
@BindView(R.id.txtName)
TextView txtName;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
}
}
The above scenario produced many errors such as unable to find view with the id,
After tons of researching I found a lot of topics discussing the same,
So after going through all the links I tried the following combinations but none of them worked
- Call
ButterKnife.bind(this)
in BaseActivity but not inSplashActivity
- Call
ButterKnife.bind(this)
in both the Activity. - Call
ButterKnife.bind(this)
inSplashActivity
, with this combination I was unable to access the BaseActivity's view items as they turned out to be null.
My Question
How do you bind both the BaseActivity
and SplashActivity
View items ?
Exact Error line
Caused by: java.lang.IllegalStateException: Required view '' with ID 2131296567 for field '' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
For your kind note, the Views exist in the layout.
Edit 1:
I have added code that overrides the setContentView();
For your kind note, the Views exist in the layout.
– NorthnorthwestFrameLayout parentContainerLayout= (FrameLayout) findViewById(R.id.parentContainerLayout); View inflated_child_layout = getLayoutInflater().inflate(layoutResID,(ViewGroup)parentContainerLayout,false); parentContainerLayout.addView(inflated_child_layout);
– Northnorthwest