2016-11-25 11 views
0

ナビゲーション・ドロワー・アクティビティのフラグメントを呼び出しています。結局、すべてのフラグメントを閉じて、フローティングボタンをクリックしてNavigation Drawer Activityのコンテンツページを表示したいと思います。そのコードは何ですか?ワンクリックですべてのフラグメントを閉じ、アクティビティに戻る

 import android.content.Intent; 
     import android.content.SharedPreferences; 
     import android.os.Bundle; 
     import android.support.design.widget.FloatingActionButton; 
     import android.support.design.widget.Snackbar; 
     import android.support.v4.app.Fragment; 
     import android.support.v4.app.FragmentManager; 
     import android.support.v4.content.ContextCompat; 
     import android.view.View; 
     import android.support.design.widget.NavigationView; 
     import android.support.v4.view.GravityCompat; 
     import android.support.v4.widget.DrawerLayout; 
     import android.support.v7.app.ActionBarDrawerToggle; 
     import android.support.v7.app.AppCompatActivity; 
     import android.support.v7.widget.Toolbar; 
     import android.view.Menu; 
     import android.view.MenuItem; 
     import android.view.Window; 
     import android.view.WindowManager; 
     import android.widget.ArrayAdapter; 
     import android.widget.ImageButton; 
     import android.widget.ImageView; 
     import android.widget.ListView; 
     import android.widget.TextView; 

public class Manager extends AppCompatActivity 
     implements NavigationView.OnNavigationItemSelectedListener,View.OnClickListener { 
    Data dat=new Data(); 
    private ImageView imageView; 
    private ImageButton logout,viewlibrary; 
    TextView headerTitle; 
    FragmentManager fragmentManager; 
    String manager=""; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_manager); 
     headerTitle=(TextView)findViewById(R.id.headertitle); 
     headerTitle.setText("Manager's Panel"); 
     TextView tv=(TextView)findViewById(R.id.usrmsgman); 
     tv.setText("USER : "+dat.getUser()); 
     logout=(ImageButton)findViewById(R.id.logoutbut); 
     viewlibrary=(ImageButton)findViewById(R.id.libview); 
/* 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     */ 
     ListView lv=(ListView)findViewById(R.id.listView); 
     Downloader d=new Downloader(this,dat.getHost()+"managerhome.php",lv); 
     d.execute(); 
     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       /* 
--------------------------------------------------------------------------- 
--------------------------------------------------------------------------- 
--------------------------------------------------------------------------- 
What to do here? 
--------------------------------------------------------------------------- 
--------------------------------------------------------------------------- 
--------------------------------------------------------------------------- 


*/ 
      }); 

      logout.setOnClickListener(this); 
      viewlibrary.setOnClickListener(this); 
      NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
      navigationView.setNavigationItemSelectedListener(this); 
     } 

     @Override 
     public void onClick(View v) { 
      switch (v.getId()) 
      { 
       case R.id.logoutbut : 
        SharedPreferences sp=getSharedPreferences("Login", 0); 
        SharedPreferences.Editor Ed=sp.edit(); 
        Ed.putString("Unm",null); 
        Ed.putString("Psw",null); 
        Ed.putString("app",null); 
        Ed.commit(); 
        this.finish(); 
        startActivity(new Intent(Manager.this,Login.class)); 
        break; 
       case R.id.libview : 
        startActivity(new Intent(this,ViewLibrary.class)); 
        break; 
      } 
     } 

     @Override 
     public void onBackPressed() { 
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
      if (drawer.isDrawerOpen(GravityCompat.START)) { 
       drawer.closeDrawer(GravityCompat.START); 
      } else { 
       super.onBackPressed(); 
      } 
     } 
    public void removeFragment(Fragment fragment){ 
     android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); 
     android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 

     fragmentTransaction.remove(fragment); 
     fragmentTransaction.commit(); 
    } 

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

     if (id == R.id.nav_issue) { 
      IssueFragment issueFragment=new IssueFragment(); 
      FragmentManager manager=getSupportFragmentManager(); 
      fragmentManager=manager; 
      manager.beginTransaction().replace(R.id.reloutForFragment,issueFragment).commit(); 
     } else if (id == R.id.nav_reissue) { 
      RIssueFragment rissueFragment = new RIssueFragment(); 
      FragmentManager manager=getSupportFragmentManager(); 
      fragmentManager=manager; 
      manager.beginTransaction().replace(R.id.reloutForFragment, rissueFragment).commit(); 

     } else if (id == R.id.nav_retbook) { 
      ReturnFragment returnFragment= new ReturnFragment(); 
      FragmentManager manager=getSupportFragmentManager(); 
      fragmentManager=manager; 
      manager.beginTransaction().replace(R.id.reloutForFragment,returnFragment).commit(); 

     } else if (id == R.id.nav_search) { 
      SearchFragment searchFragment= new SearchFragment(); 
      FragmentManager manager=getSupportFragmentManager(); 
      fragmentManager=manager; 
      manager.beginTransaction().replace(R.id.reloutForFragment,searchFragment).commit(); 

     } else if (id == R.id.nav_abtApp) { 
      AbtAppFragment abtAppFragment=new AbtAppFragment(); 
      FragmentManager manager=getSupportFragmentManager(); 
      fragmentManager=manager; 
      manager.beginTransaction().replace(R.id.reloutForFragment,abtAppFragment).commit(); 

     } else if (id == R.id.nav_abtDev) { 
      AbtDevFragment abtDevFragment= new AbtDevFragment(); 
      FragmentManager manager=getSupportFragmentManager(); 
      fragmentManager=manager; 
      manager.beginTransaction().replace(R.id.reloutForFragment,abtDevFragment).commit(); 

     } else if (id == R.id.nav_view_mem) { 
      ViewMemberFragment viewMemberFragment= new ViewMemberFragment(); 
      FragmentManager manager=getSupportFragmentManager(); 
      fragmentManager=manager; 
      manager.beginTransaction().replace(R.id.reloutForFragment,viewMemberFragment).commit(); 

     } else if (id == R.id.nav_log) { 
      LogFragment logFragment= new LogFragment(); 
      FragmentManager manager=getSupportFragmentManager(); 
      fragmentManager=manager; 
      manager.beginTransaction().replace(R.id.reloutForFragment,logFragment).commit(); 

     } 

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

私は

Intent intent = getIntent(); 
finish(); 
startActivity(intent); 

を行うことができますしかし、私は

答えて

0

がメインレイアウトのフラグメントを作成し、あなたの活動はそのような活動への主なフラグメントを追加起動時に活動を再開したくありません:

if (savedInstanceState == null) { 
     getSupportFragmentManager().beginTransaction() 
      .replace(R.id.reloutForFragment, fragment) 
      .commit(); 
} 

フロートアクションボタンをクリックして同じコードを呼び出すと。

関連する問題