0

ナビゲーション・ドロワー・アクティビティ内でタブビューを作成しました。私はそれを管理するために単純なフラグメントページアダプタを使用しました。問題は私のタブが見えないことです。 activity_main.xmlにはナビゲーションドロワーが含まれているので、content_main.xmlを使用してタブビューとviewPagerを作成しました。アダプタのタブビューにタブが表示されない

コードは、MainActivityのため

public class SimpleFragmentPageAdapter extends FragmentPagerAdapter { 
private String[] tabtitle=new String[]{"Tab1", "Tab2", "Tab3"}; 
Context context; 
private int pagecount=3; 
public SimpleFragmentPageAdapter(FragmentManager fm, Context context) { 
    super(fm); 
    this.context=context; 
} 

@Override 
public CharSequence getPageTitle(int position) { 
    return tabtitle[position]; 
} 

@Override 
public Fragment getItem(int position) { 
    switch (position) { 

     // Open FragmentTab1.java 
     case 0: 
      FragmentSc fragmentSc = new FragmentSc(); 
      return fragmentSc; 

     // Open FragmentTab2.java 
     case 1: 
      Entertainment entertainment = new Entertainment(); 
      return entertainment; 

     // Open FragmentTab3.java 
     case 2: 
      Sports sports = new Sports(); 
      return sports; 
    } 
    return null; 
} 

@Override 
public int getCount() { 
    return 0; 
} 


} 

コードです。

public class MainActivity extends AppCompatActivity 
    implements NavigationView.OnNavigationItemSelectedListener { 


TabLayout tabLayout; 

/** 
* ATTENTION: This was auto-generated to implement the App Indexing API. 
* See https://g.co/AppIndexing/AndroidStudio for more information. 
*/ 
private GoogleApiClient client; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

    final ViewPager viewPager= (ViewPager) findViewById(R.id.view_pager); 
    viewPager.setAdapter(new SimpleFragmentPageAdapter(getSupportFragmentManager(),this)); 

    tabLayout= (TabLayout) findViewById(R.id.tab_layout); 
    tabLayout.setupWithViewPager(viewPager); 


    getSupportActionBar().setTitle(null); 
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
    fab.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
        .setAction("Action", null).show(); 
     } 
    }); 

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
    drawer.setDrawerListener(toggle); 
    toggle.syncState(); 

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
    navigationView.setNavigationItemSelectedListener(this); 



    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, 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); 
} 

private void dispaySelectedScreen(int id) { 
    Fragment fragment = null; 

    switch (id) { 
     case R.id.facebook_login: 
      fragment = new FacebookLogin(); 
      break; 
     case R.id.memes: 
      fragment = new Memes(); 
      break; 
     case R.id.submit_image: 
      fragment = new SubmitImage(); 
      break; 
     case R.id.discussion: 
      fragment = new Discussions(); 
      break; 
     case R.id.invite: 
      fragment = new Invite(); 
      break; 
     case R.id.connect_fb: 
      fragment = new FacebookConnect(); 
      break; 
     case R.id.connect_twitter: 
      fragment = new TwitterConnect(); 
      break; 
     case R.id.connect_instagram: 
      fragment = new InstaConnect(); 
      break; 
    } 

    if (fragment != null) { 
     FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); 
     ft.replace(R.id.content_main, fragment); 
     ft.addToBackStack(null); 
     ft.commit(); 




    } 

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    drawer.closeDrawer(GravityCompat.START); 









} 



@SuppressWarnings("StatementWithEmptyBody") 
@Override 
public boolean onNavigationItemSelected(MenuItem item) { 
    // Handle navigation view item clicks here. 
    int id = item.getItemId(); 


    dispaySelectedScreen(id); 
    return true; 
} 

/** 
* ATTENTION: This was auto-generated to implement the App Indexing API. 
* See https://g.co/AppIndexing/AndroidStudio for more information. 
*/ 
public Action getIndexApiAction() { 
    Thing object = new Thing.Builder() 
      .setName("Main Page") // TODO: Define a title for the content shown. 
      // TODO: Make sure this auto-generated URL is correct. 
      .setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]")) 
      .build(); 
    return new Action.Builder(Action.TYPE_VIEW) 
      .setObject(object) 
      .setActionStatus(Action.STATUS_TYPE_COMPLETED) 
      .build(); 
} 

@Override 
public void onStart() { 
    super.onStart(); 

    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    client.connect(); 
    AppIndex.AppIndexApi.start(client, getIndexApiAction()); 
} 

@Override 
public void onStop() { 
    super.onStop(); 

    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    AppIndex.AppIndexApi.end(client, getIndexApiAction()); 
    client.disconnect(); 
} 


} 

私は何が欠けているのかをお勧めします。

答えて

0

それを手に入れた...私はGETCOUNTオーバーライドメソッドを逃した..私は戻りPAGECOUNTを渡す必要が

...

作業
関連する問題