I am working on Android Project where I need to give a tabs in a page, So I am using Fragments for the same, I have successfully created fragments, But in the main page where I've code to join all fragment, its giving error that
'Wrong 1st argument type. Found: 'com.android.mads.madses.LoginInfoFragment', required: 'android.support.v4.app.Fragment' less... addFrag (android.support.v4.app.Fragment, String) in ViewPagerAdapter cannot be applied to (com.android.mads.madses.LoginInfoFragment, String)'
I am not getting what exactly the error it. Can anyone help me out with this please?
Here is the complete java code
package com.android.mads.madses;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import java.util.ArrayList;
import java.util.List;
import com.android.mads.madses.LoginInfoFragment;
import com.android.mads.madses.VechicleInfoFragment;
import com.android.mads.madses.PersonalInfoFragment;
import com.android.mads.madses.ContactInfoFragment;
public class RegisterActivity extends AppCompatActivity {
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFrag(new LoginInfoFragment(), "LoginInfo");
adapter.addFrag(new PersonalInfoFragment(), "PersonalInfo");
adapter.addFrag(new ContactInfoFragment(), "ContactInfo");
adapter.addFrag(new VechicleInfoFragment(), "VechicleInfo");
viewPager.setAdapter(adapter);
}
class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFrag(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
}