gpt4 book ai didi

java - 无法解析符号 setOnPageChangeListener

转载 作者:行者123 更新时间:2023-11-29 03:07:13 25 4
gpt4 key购买 nike

我找不到任何与我的场景相关的解决方案。我正在努力在选项卡滑动上手动选择受尊重的选项卡。我正在学习

http://www.androidgreeve.com/2014/01/android-actionbar-navigating-with-swipeable-tabs-and-views.html

在 MainActivity 中,在添加 viewPager.setOnPageChangeListener 时它无法识别它......它会报错......

cannot resolve symbol setOnPageChangeListener

这是代码

package com.example.administrator.fragmentsexample;

import android.support.v7.app.ActionBar;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.example.administrator.adapter.TabsPagerAdapter;

public class MainActivity extends AppCompatActivity implements
ActionBar.TabListener {

private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
// Tab titles
private String[] tabs = {"Social", "Organizer", "Movies"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Initilization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getSupportActionBar();
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));

}
}

@Override
public void onTabSelected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction fragmentTransaction) {

}

@Override
public void onTabUnselected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction fragmentTransaction) {

}

@Override
public void onTabReselected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction fragmentTransaction) {

}

viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

@Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}

@Override
public void onPageScrollStateChanged(int arg0) {
}
});

}

我错过了什么?

最佳答案

试着移动这个:

viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

@Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}

@Override
public void onPageScrollStateChanged(int arg0) {
}
});

进入onCreate。我认为当前的通话安排没有意义。 :-)

关于java - 无法解析符号 setOnPageChangeListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31562760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com