我收到错误
'需要不兼容的类型:android.widget.Button 找到:android.view.View'
现在这个类有一个错误......
他们说我要重命名文件,但我的代码中也有一个 MapsActivity
这是我的代码:
public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@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(map);
mapFragment.getMapAsync(this);
final Toolbar customToolbar = (Toolbar) findViewById(R.id.toolbar);
customToolbar.setTitle("Hello");
getSupportActionBar().setTitle("Titeltest");
getSupportActionBar().setDisplayShowTitleEnabled(false);
TextView mTitle = (TextView) customToolbar.findViewById(R.id.toolbar_title);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
}
public class ButtonClass extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
final Button button = (Button) findViewById(R.id.addbutton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Insert Action if clicking on button here
}
});
}
}
您必须将视图投射到按钮:
final Button button = (Button) findViewById(R.id.addbutton);
编辑:
public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
final Button button = (Button) findViewById(R.id.addbutton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Insert Action if clicking on button here
}
});
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(map);
mapFragment.getMapAsync(this);
final Toolbar customToolbar = (Toolbar) findViewById(R.id.toolbar);
customToolbar.setTitle("Hello");
getSupportActionBar().setTitle("Titeltest");
getSupportActionBar().setDisplayShowTitleEnabled(false);
TextView mTitle = (TextView) customToolbar.findViewById(R.id.toolbar_title);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句