2017-07-19 6 views
0

最初の(メイン・ページ)にはスワイプ・ギャラリーがあり、それをしましたがナビゲーション・メニューからオプションを選択するとページャ・レイアウト魔女は私のナビゲーションですただandroid.support.v4.view.ViewPagerが含まれているcuzを引き出しレイアウトとその空白ナビゲーション・ドロワーのViewPager - アドバイスをお願いします

CONTENT_MAIN.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.view.ViewPager 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:id="@+id/pager" 

app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.example.marcj.justtest.drawer" 
> 
</android.support.v4.view.ViewPager> 

しかし、今、私はそこにオプションの上で選択した私のナビゲーション引き出しに行きたいと他のスワッピングギャラリー..持っているが、私はホーを知らないオプションを選択したときなどに行うw 売り切れ空白のレイアウトがあります。

enter image description here

drawer.javaファイル:

package com.example.marcj.justtest; 

import java.math.BigDecimal; 

public class drawer extends AppCompatActivity implements   
NavigationView.OnNavigationItemSelectedListener { 

ViewPager viewPager; 

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

    viewPager = (ViewPager) findViewById(R.id.pager); 
    PageAdapter padapter = new PageAdapter(getSupportFragmentManager()); 
    viewPager.setAdapter(padapter); 





    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 



    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.addDrawerListener(toggle); 
    toggle.syncState(); 

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

    View headerView = navigationView.getHeaderView(0); 

    String username = getIntent().getStringExtra("username"); 

    TextView text2 = (TextView) headerView.findViewById(R.id.TVusername); 
    text2.setText(username); 



} 








@Override 
public void onBackPressed() { 
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    if (drawer.isDrawerOpen(GravityCompat.START)) { 
     drawer.closeDrawer(GravityCompat.START); 
    } else { 
     super.onBackPressed(); 
    } 
} 


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

    } else if (id == R.id.action_contact) { 

     Toast.makeText(this, "Contact Form", Toast.LENGTH_SHORT).show(); 


     Intent i = new Intent(drawer.this, AcContact.class); 
     startActivity(i); 

     contact contactForm = new contact(); 
     FragmentManager manager = getSupportFragmentManager(); 
     manager.beginTransaction().replace(R.id.pager, 
       contactForm, contactForm.getTag()).commit(); 

    } else if (id == R.id.nav_clicked) { 
    } 

    return super.onOptionsItemSelected(item); 
} 

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

    if (id == R.id.nav_homepage) { 

     Intent i= new Intent (drawer.this, drawer.class); 
     startActivity(i); 

} else if (id == R.id.nav_clicked) { 
     Toast.makeText(this, "Clicked Items", Toast.LENGTH_SHORT).show(); 

     clicked clickedItems = new clicked(); 
     FragmentManager manager = getSupportFragmentManager(); 
     manager.beginTransaction().replace(R.id.pager, 
       clickedItems, clickedItems.getTag()).commit(); 


    } else if (id == R.id.nav_won) { 
     Toast.makeText(this, "Won Items", Toast.LENGTH_SHORT).show(); 

     won wonItems = new won(); 
     FragmentManager manager = getSupportFragmentManager(); 
     manager.beginTransaction().replace(R.id.pager, 
       wonItems, wonItems.getTag()).commit(); 

    } else if (id == R.id.nav_selling) { 
     Toast.makeText(this, "Item that you Selling", 
    Toast.LENGTH_SHORT).show(); 

     selling sellingItems = new selling(); 
     FragmentManager manager = getSupportFragmentManager(); 
     manager.beginTransaction().replace(R.id.pager, 
       sellingItems, sellingItems.getTag()).commit(); 

    } else if (id == R.id.nav_sold) { 
     Toast.makeText(this, "Sold Items", Toast.LENGTH_SHORT).show(); 

     sold soldItems = new sold(); 
     FragmentManager manager = getSupportFragmentManager(); 
     manager.beginTransaction().replace(R.id.pager, 
       soldItems, soldItems.getTag()).commit(); 

    } else if (id == R.id.nav_topup) { 
     Toast.makeText(this, "Top-Up Clicks", Toast.LENGTH_SHORT).show(); 

     topup topupItems = new topup(); 
     FragmentManager manager = getSupportFragmentManager(); 
     manager.beginTransaction().replace(R.id.pager, 
       topupItems, topupItems.getTag()).commit(); 

    } else if (id == R.id.nav_share) { 





    } 

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

PageAdapter.java

package com.example.marcj.justtest; 

import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentPagerAdapter; 


public class PageAdapter extends FragmentPagerAdapter { 

public PageAdapter (FragmentManager fm){ 

    super(fm); 
} 

public Fragment getItem (int arg0){ 

    switch (arg0){ 

     case 0: 
      return new FragmentOne(); 

     case 1: 
      return new FragmentTwo(); 

     case 2: 
      return new FragmentThree(); 


     default: 
      break; 
    } 

    return null; 
} 



public int getCount(){ 

    return 3; 
} 
} 

Activity_drawer.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<include 
    layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<android.support.v4.view.ViewPager 
    android:id="@+id/view_pager" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 

    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_drawer_menu" /> 

</android.support.v4.widget.DrawerLayout> 

app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context=".drawer"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme" /> 

</android.support.design.widget.AppBarLayout> 

<include layout="@layout/content_main" /> 



</android.support.design.widget.CoordinatorLayout> 

activity_drawer.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<include 
    layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<android.support.v4.view.ViewPager 
    android:id="@+id/view_pager" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 

    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_drawer_menu" /> 

</android.support.v4.widget.DrawerLayout> 
+0

くださいPOS activity_drawer.xmlファイル。 –

+0

アイデア? :) @ManiKandanSelvanathan –

答えて

0

activity_drawerファイル:

android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<include 
    layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<android.support.v4.view.ViewPager 
    android:id="@+id/view_pager" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_drawer_menu" /> 

content_main

android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:id="@+id/pager" 

app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.example.marcj.justtest.drawer" 
> 
関連する問題