title: viewPager and data binding android
body: <p>I have a activity with a view pager and i implements MVVM.<br>
  I can't set view pager adapter. 
  I read all of the post in stack Over Flow but i have error.
  which part of my code is wrong?
  I posted all of the my codes.</p>
  
  <blockquote>
    <p>This my xml codes</p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layout xmlns:bind="http://schemas.android.com/tools"&gt;
  &lt;data&gt;
      &lt;variable
          name="main"
          type="ir.****.viewmodel.MainViewModel" /&gt;
  &lt;/data&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:orientation="vertical"&gt;
  &lt;include
      android:id="@+id/toolbar"
      layout="@layout/toolbar"/&gt;
  
  &lt;androidx.viewpager.widget.ViewPager
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      adapter="@{main}" /&gt;
  
  &lt;com.google.android.material.bottomnavigation.BottomNavigationView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:itemTextColor="@android:color/transparent"
      app:menu="@menu/main_menu" /&gt;
  </code></pre>
  
  <p>
  </p>
  
  <blockquote>
    <p>This is my viewModel codes</p>
  </blockquote>
  
  <pre><code>public class MainViewModel extends BaseObservable {
  private  AppCompatActivity activity;
  
  public MainViewModel(AppCompatActivity activity) {
      this.activity = activity;
  }
  
  @BindingAdapter("adapter")
  public static void setViewPagerFragments(ViewPager pager , MainViewModel viewModel){
      pager.setAdapter(new MyFragmentAdapter(pager.getContext() , viewModel.activity.getSupportFragmentManager() ));
  }
  }
  </code></pre>
  
  <blockquote>
    <p>This is my mainActivity Codes</p>
  </blockquote>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      ActivityMainBinding mainBinding = DataBindingUtil.setContentView(this , R.layout.activity_main);
      MainViewModel viewModel = new MainViewModel(this);
      mainBinding.setMain(viewModel);
  }
  }
  </code></pre>
  
  <blockquote>
    <p>This is my fragment adapter codes</p>
  </blockquote>
  
  <pre><code>public class MyFragmentAdapter extends FragmentPagerAdapter {
  private static final int TRADE = 0;
  
  private static final int[] TABS = new int[]{TRADE};
  
  private Context mContext;
  
  public MyFragmentAdapter(final Context context, final FragmentManager fm) {
      super(fm);
      mContext = context;
  }
  
  @Override
  public Fragment getItem(int position) {
      switch (TABS[position]) {
          case TRADE:
              return TradeFragment.newInstance("first", "first");
      }
      return null;
  }
  
  @Override
  public int getCount() {
      return TABS.length;
  }
  
  @Override
  public CharSequence getPageTitle(int position) {
      switch (TABS[position]) {
          case TRADE:
              return mContext.getResources().getString(R.string.trade);
      }
      return null;
  }
  }
  </code></pre>
  
  <blockquote>
    <p>and logcat message after crush</p>
  </blockquote>
  
  <pre><code>    java.lang.IllegalStateException: ViewPager with adapter ir.****.Adapter.MyFragmentAdapter@a0ef1f requires a view id
  </code></pre>