-2

私はこのマップアクティビティを持っており、ナビゲーションバー/ドロワを作成したいと思います。 ありますMapsActivityの誤差は(マップアクティビティでナビゲーションバーを作成するAndroid

MapsActivity.java

public class MapsActivity extends FragmentActivity implements 
OnMapReadyCallback { 

String [] places= {"bais city","basay","bindoy"}; 
AutoCompleteTextView textview; 

private GoogleMap mMap; 
private LatLng latLng; 
private Marker marker; 

private Toolbar category; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_maps); 
    // Obtain the SupportMapFragment and get notified when the map is ready 
     to be used. 
    SupportMapFragment mapFragment = (SupportMapFragment) 
     getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 

    category = (Toolbar) findViewById(R.id.Navbar); 
    setSupportActionBar(category); //i got my error here says cannot resolve 
    method 

} 

輸入

import android.content.DialogInterface; 
import android.location.Address; 
import android.location.Geocoder; 
import android.preference.DialogPreference; 
import android.support.v4.app.FragmentActivity; 
import android.os.Bundle; 
import android.support.v7.app.ActionBarActivity; 
import android.support.v7.app.AlertDialog; 
import android.support.v7.widget.Toolbar; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.AutoCompleteTextView; 
import android.widget.EditText; 
import android.widget.TextView; 

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.OnMapReadyCallback; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.LatLngBounds; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 

import java.io.IOException; 
import java.util.List; 
import java.util.Locale; 

地図アクティビティレイアウト "メソッドsetSupportActionBar(android.support.v7.widget.Toolbar)を解決することはできません" と言いますxml)

<!--suppress ALL --> 
<LinearLayout xmlns:map="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical"> 
<TextView 
    android:text="@string/test" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/PSString" 
    android:textSize="22sp"/> 


<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

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


    <AutoCompleteTextView 
     android:layout_width="278dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/autoCompleteTextView" 
     tools:ignore="LabelFor" /> 

    <Button 
     android:text="@string/search" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/BTNSearch" 
     android:layout_gravity="end" 
     android:onClick="onSearch" /> 

    <fragment 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="384dp" 
     android:layout_height="554dp" 
     tools:context="com.example.boneyflesh.homepage.MapsActivity" 
     tools:layout="@layout/activity_main" /> 
    </LinearLayout> 



</LinearLayout> 

Navbar layout(xml)

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar  
xmlns:android="http://schemas.android.com/apk/res/android" 

android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:id="@+id/Navbar"> 

</android.support.v7.widget.Toolbar> 

MainActivity

public class MainActivity extends AppCompatActivity { 

public void whatodo(View view){ 
    if(view.getId() == R.id.BTNStart){ 
     AlertDialog.Builder prompt = new 
     AlertDialog.Builder(MainActivity.this); 
     prompt.setCancelable(false) 
       .setPositiveButton("Documents", new 
        DialogInterface.OnClickListener() { 
          @Override 
          public void onClick(DialogInterface dialog, int 
          which) { 

          } 
         } 
       ) 
        .setNegativeButton("2D MAP", new 
        DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, int 
         which) { 
          startActivity(new 
         Intent(getApplicationContext(),MapsActivity.class)); 
         } 
        } 
        ); 


     AlertDialog alert = prompt.create(); 
     alert.setTitle("Please select an option"); 
     alert.show(); 

    } 
    if(view.getId() == R.id.BTNInfo){ 

    } 
    if(view.getId() == R.id.BTNClose){ 
     finish(); 
     System.exit(0); 
    } 
} 


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

} 

}

答えて

0

その方法は、FragmentActivityに実装されていないのでsetSupportActionBar()メソッドを解決できません。理想的には、AppCompatActivityからアクティビティを継承する必要があります。これにより、ツールバーやフラグメントを扱うことができます。

+0

ive私の記事を編集しました。本当にこの物に新しいですが、どうすればMainActivityのセットアップでそれをやりますか? iveは、マップアクティビティを開くために[警告]ダイアログボックスで[my]を設定します。 – Boneyflesh

+0

... 'extends FragmentActivity'ではなく' extends AppCompatActivity'でなければなりません。 –

+0

おかげで、エラーがなくなったが、まだナビゲーションバーを引き出す方法で苦労している。 :いいぞ: – Boneyflesh

関連する問題