2016-03-29 11 views
-2

ガイドアプリを作成していて、他のユーザーがナビゲーションドロワーのアイテムをタップするようにするには、どうすれば別のアクティビティを開くことができますか? これはMainApplication.javaです:ナビゲーションドロワーのアイテムを使用して他のアクティビティを開く方法

package net.agiann.paliachora_guide; 

import android.app.Application; 
import android.test.ApplicationTestCase; 

    /** 
    * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> 
    */ 
    public class ApplicationTest extends ApplicationTestCase<Application> { 
     public ApplicationTest() { 
      super(Application.class); 
     } 
    } 
+0

NavigationView.OnNavigationItemSelectedListenerあなたの活動を実装アクティビティコード。 –

+0

あなたの質問が正しいかどうかわかりません。しかし、ナビゲーション・ドロウ・メニュー項目のクリックで新しいアクティビティを開くには、インテントを使用して実装する必要があります。新しいアクティビティがアクティビティスタックの現在の上に表示されます。 – user1122549

答えて

1
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { 

      // This method will trigger on item Click of navigation menu 
      @Override 
      public boolean onNavigationItemSelected(MenuItem menuItem) { 


       //Checking if the item is in checked state or not, if not make it in checked state 
       if (menuItem.isChecked()) menuItem.setChecked(false); 
       else menuItem.setChecked(true); 

       //Closing drawer on item click 
       drawerLayout.closeDrawers(); 

       //Check to see which item was being clicked and perform appropriate action 
       switch (menuItem.getItemId()) { 


        //Replacing the main content with ContentFragment Which is our Inbox View; 
        case R.id.drawer_home: 

         Intent intent=new Intent(HomeActivity.this, HomeActivity.class); 
         startActivity(intent); 

         finish(); 
         return true; 

        // For rest of the options we just show a toast on click 


        default: 
         Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show(); 
         return true; 

       } 
      } 
     }); 
0

これを試してみてください。

あなたが、ここではテストスイートを掲載しませ

public boolean onNavigationItemSelected(MenuItem item) { 
    // Handle navigation view item clicks here. 
    int resultCode = GooglePlayServicesUtil 
      .isGooglePlayServicesAvailable(this); 
    int id = item.getItemId(); 

    if (id == R.id.nav_home) { 
     Intent intent=new Intent(this,HomeActivity.class); 
     startActivity(intent); 
    }else if(second codition){ 

    } 

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    drawer.closeDrawer(GravityCompat.START); 
    return true; 
} 
0
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { 
      @Override 
      public boolean onNavigationItemSelected(MenuItem menuItem) { 
       mDrawerLayout.closeDrawers(); 
       switch (menuItem.getItemId()) { 
        case R.id.nav_item_Animation: 
         Intent intent=new Intent(this,MainActivity.class); 
    startActivity(intent); 
         break; 
        case R.id.nav_item_loginScreen: 
         Intent intent=new Intent(this,LoginActivity.class); 
    startActivity(intent); 
         break; 
} 
       return false; 
}); 
関連する問題