public class NewActivity extends AppCompatActivity {
ViewPager vp;
Myadapter madapter;
TextView but_zy,but_pb,but_wd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_new);
vp= (ViewPager) findViewById(R.id.rv);
but_zy= (TextView) findViewById(R.id.but_zy);
but_pb= (TextView) findViewById(R.id.but_pb);
but_wd= (TextView) findViewById(R.id.but_wd);
madapter=new Myadapter(getSupportFragmentManager());
vp.setAdapter(madapter);
but_zy.setBackgroundColor(Color.GREEN);
but_pb.setBackgroundColor(Color.YELLOW);
but_wd.setBackgroundColor(Color.YELLOW);
vp.setCurrentItem(0);
but_zy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
vp.setCurrentItem(0);
}
});
but_pb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
vp.setCurrentItem(1);
}
});
but_wd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
vp.setCurrentItem(2);
}
});
vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
switch (position)
{
case 0:
but_zy.setBackgroundColor(Color.GREEN);
but_pb.setBackgroundColor(Color.YELLOW);
but_wd.setBackgroundColor(Color.YELLOW);
break;
case 1:
but_pb.setBackgroundColor(Color.GREEN);
but_zy.setBackgroundColor(Color.YELLOW);
but_wd.setBackgroundColor(Color.YELLOW);
break;
case 2:
but_wd.setBackgroundColor(Color.GREEN);
but_zy.setBackgroundColor(Color.YELLOW);
but_pb.setBackgroundColor(Color.YELLOW);
break;
}
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
class Myadapter extends FragmentPagerAdapter{
public Myadapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fm=null;
switch (position)
{
case 0:
fm=new ZYFagment();
break;
case 1:
fm=new PPFagment();
break;
case 2:
fm=new WDFagment();
break;
}
return fm;
}
@Override
public int getCount() {
return 3;
}
}
}
ViewPager vp;
Myadapter madapter;
TextView but_zy,but_pb,but_wd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_new);
vp= (ViewPager) findViewById(R.id.rv);
but_zy= (TextView) findViewById(R.id.but_zy);
but_pb= (TextView) findViewById(R.id.but_pb);
but_wd= (TextView) findViewById(R.id.but_wd);
madapter=new Myadapter(getSupportFragmentManager());
vp.setAdapter(madapter);
but_zy.setBackgroundColor(Color.GREEN);
but_pb.setBackgroundColor(Color.YELLOW);
but_wd.setBackgroundColor(Color.YELLOW);
vp.setCurrentItem(0);
but_zy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
vp.setCurrentItem(0);
}
});
but_pb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
vp.setCurrentItem(1);
}
});
but_wd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
vp.setCurrentItem(2);
}
});
vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
switch (position)
{
case 0:
but_zy.setBackgroundColor(Color.GREEN);
but_pb.setBackgroundColor(Color.YELLOW);
but_wd.setBackgroundColor(Color.YELLOW);
break;
case 1:
but_pb.setBackgroundColor(Color.GREEN);
but_zy.setBackgroundColor(Color.YELLOW);
but_wd.setBackgroundColor(Color.YELLOW);
break;
case 2:
but_wd.setBackgroundColor(Color.GREEN);
but_zy.setBackgroundColor(Color.YELLOW);
but_pb.setBackgroundColor(Color.YELLOW);
break;
}
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
class Myadapter extends FragmentPagerAdapter{
public Myadapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fm=null;
switch (position)
{
case 0:
fm=new ZYFagment();
break;
case 1:
fm=new PPFagment();
break;
case 2:
fm=new WDFagment();
break;
}
return fm;
}
@Override
public int getCount() {
return 3;
}
}
}