title: Databinding apply for one layout used by multiple activity/fragment
body: <p>I am replacing existing code by <a href="https://developer.android.com/tools/data-binding/guide.html" rel="nofollow">databinding</a>. But I face a problem. </p>
  
  <p>I have some layout files shared by more than one activity/fragment. E.g there is a layout file <code>layout_sub</code> used by <code>SubFragmentA</code> and its extending class <code>SubFragmentB</code>. And the data model used in these two fragment are not the same.</p>
  
  <p>The code looks like following.</p>
  
  <pre><code>public class SubFragmentA extends Fragment {
  
      private DataA dataA;
  
      @Override
      public View onCreateView(Bundle Bundle) {
          View v = LayoutInflator.from(getActivity()).inflate(R.layout.shared_layout);
          initView(v, dataA);
          return v;
      }
  
      private void initView(view v, DataA dataA) {
          // use dataA to init v
      }
  }
  
  public class SubFragmentB extends Fragment {
  
      private DataB dataB;
  
      @Override
      public View onCreateView(Bundle Bundle) {
          View v = LayoutInflator.from(getActivity()).inflate(R.layout.shared_layout);
          initView(v, dataB);
          return v;
      }
  
      private void initView(view v, DataB dataB) {
          // use dataB to init v
      }
  }
  </code></pre>
  
  <p>So far, I think using DataA and DataB in <code>layout_sub</code> file at the same time is not a good idea, because it would require a lot of redundant code to decide which object to be used.</p>
  
  <p>Please share your ideas on this problem.</p>