hello guy I would like to create a Tab Layout & View Pager in android studio here is my activity_xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabIndicatorColor="@color/colorAccent"
android:id="@+id/tablayout_id"></android.support.design.widget.TabLayout>
<android.support.v4.widget.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewPager_id">
</android.support.v4.widget.view.ViewPager>
</LinearLayout>
and here is my MainActivity :
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
private TabLayout tabLayout;
private ViewPager viewPager;
private ViewPagerAdapter viewPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabLayout = (TabLayout) findViewById(R.id.tablayout_id);
viewPager = (ViewPager) findViewById(R.id.viewPager_id);
viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
viewPagerAdapter.AddFragment(new FragmentCall(),"Call"); // `new FragmentCall()` should be inside `FragmentPagerAdapter.getItem()`
viewPagerAdapter.AddFragment(new FragmentContact(), "Contact"); // `new FragmentContact()` should be inside `FragmentPagerAdapter.getItem()`
viewPagerAdapter.AddFragment(new FragmentFav(), "Fav"); // `new FragmentFav()` should be inside `FragmentPagerAdapter.getItem()`
viewPager.setAdapter(viewPagerAdapter);
tabLayout.setupWithViewPager(viewPager);
}
}
the error say : Binary XML file line #18: Binary XML file line #18: Error inflating class android.support.v4.widget.view.ViewPager and : Didn't find class "android.support.v4.widget.view.ViewPager I've ever to search this error in this link : Error inflating class android.support.v4.view.ViewPager, but I do not understand how to resolve the error, he say Right click on the jar, then select Build Path and click on Add to Build Path. And I do not understand how to select Build Path.