2016-06-21 9 views
-4

こんにちは私はアプリを作っており、レイアウトでナビゲーションドロワーとGoogleマップアクティビティを一緒に実装することはできません。私はオラのアプリが動くようなナビゲーション・ドロワーにマップ・アクティビティーを追加したい。ナビゲーションドロワーとGoogleマップアクティビティを一緒に実装する方法

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_map); 
    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); 

    Intent intent9 = new Intent(this, Maps.class); 
    startActivity(intent9);// Adding map activity 

} 

@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.map, 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); 
} 

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

     Intent intent5 = new Intent(this, ScheduledTimings.class); 
     startActivity(intent5); 
    } 
    else if (id == R.id.nav_contact) { 

     Intent intent6 = new Intent(this, EmergencyContact.class); 
     startActivity(intent6); 
    } 
    else if (id==R.id.nav_feedback){ 
     Intent intent10 = new Intent(this, Feedback.class); 
     startActivity(intent10); 
    } 
    else if (id == R.id.nav_about) { 

     Intent intent7 = new Intent(this, About.class); 
     startActivity(intent7); 
    } 

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

これまでに試したことをお聞かせください。 –

+0

フラグメント内のMapViewを使用し、ナビゲーション・ドロワが実装されているメイン・アクティビティでそのフラグメントを使用します –

答えて

0

あなたは何をしようとしましたか?上のコードでは、引き出し実装のみを示していますが、マップについてはどうですか?

私はあなたがこの方法を行うにお勧め:

ここでは、主な活動の引き出しを実装するには、フラグメントを使用してフラグメントでのMapViewを挿入します。

関連する問題