//主方法implements OnClickListener点击得出下面这个方法
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_one:
vp2.setCurrentItem(0);
tv_one.setTextColor(Color.RED);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.BLACK);
break;
case R.id.tv_two:
vp2.setCurrentItem(1);
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.RED);
tv_three.setTextColor(Color.BLACK);
break;
case R.id.tv_three:
vp2.setCurrentItem(2);
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.RED);
break;
default:
break;
}
}
//设置点击事件
public void tv_onclick(){
tv_one=(TextView) findViewById(R.id.tv_one);
tv_two=(TextView) findViewById(R.id.tv_two);
tv_three=(TextView) findViewById(R.id.tv_three);
tv_one.setTextColor(Color.RED);
tv_one.setOnClickListener(this);
tv_two.setOnClickListener(this);
tv_three.setOnClickListener(this);
}
vp2.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
if(arg0==0){
tv_one.setTextColor(Color.RED);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.BLACK);
}else if(arg0==1){
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.RED);
tv_three.setTextColor(Color.BLACK);
}else if(arg0==2){
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.RED);
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_one:
vp2.setCurrentItem(0);
tv_one.setTextColor(Color.RED);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.BLACK);
break;
case R.id.tv_two:
vp2.setCurrentItem(1);
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.RED);
tv_three.setTextColor(Color.BLACK);
break;
case R.id.tv_three:
vp2.setCurrentItem(2);
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.RED);
break;
default:
break;
}
}
//设置点击事件
public void tv_onclick(){
tv_one=(TextView) findViewById(R.id.tv_one);
tv_two=(TextView) findViewById(R.id.tv_two);
tv_three=(TextView) findViewById(R.id.tv_three);
tv_one.setTextColor(Color.RED);
tv_one.setOnClickListener(this);
tv_two.setOnClickListener(this);
tv_three.setOnClickListener(this);
}
vp2.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
if(arg0==0){
tv_one.setTextColor(Color.RED);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.BLACK);
}else if(arg0==1){
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.RED);
tv_three.setTextColor(Color.BLACK);
}else if(arg0==2){
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.RED);
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});