간단한 탭 스 와이프를 초기화하려고하는데, PagerAdapter를 추가 할 때 getItem 메소드가 호출되지 않습니다. 이 이유는 찾을 수 없습니다.FragmentPagerAdapter GetItem은 호출되지 않습니다?
활동 :
public class ProfileActivity extends Activity implements ActionBar.TabListener
{
ViewPager viewPager;
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_acivity);
viewPager = (ViewPager) findViewById(R.id.profile_view_pager);
ProfilePagerAdapter viewPagerAdapter = new ProfilePagerAdapter(getFragmentManager());
viewPager.setAdapter(viewPagerAdapter);
viewPager.setCurrentItem(0);
actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab friendsTab = actionBar.newTab();
ActionBar.Tab postsTab = actionBar.newTab();
ActionBar.Tab tribesTab = actionBar.newTab();
tribesTab.setText("TRIBES");
postsTab.setText("POSTS");
friendsTab.setText("FRIENDS");
tribesTab.setTabListener(this);
postsTab.setTabListener(this);
friendsTab.setTabListener(this);
actionBar.addTab(friendsTab);
actionBar.addTab(postsTab);
actionBar.addTab(tribesTab);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_profile_acivity, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
{
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
{
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
{
}
}
(나는 또한 내가 V4 필요하지 않습니다와 나는 V13을 사용하고 FragmentActivity 비록 함께 시도)
내 어댑터 :
private class ProfilePagerAdapter extends FragmentPagerAdapter
{
Fragment fragment = new ProfileTribeFragment();
public ProfilePagerAdapter(FragmentManager fm)
{
super(fm);
}
@Override
public Fragment getItem(int i)
{
Log.i("D","NO :{");
if(i==0)
{
fragment = new ProfileFriendsFragment();
}
if(i==1)
{
fragment = new ProfilePostsFragment();
}
if(i==2)
{
fragment = new ProfileTribeFragment();
}
return fragment;
}
@Override
public int getCount()
{
return 0;
}
}
그리고 모든 3 개의 조각은 다음과 같이 보입니다.
}
나는 잘못 생각하고있다. getItem의 Log.i가 절대로 표시되지 않습니다.
오 와우 그 날의 바보! 감사! – Eladit
실수가 발생했습니다.) –