많은 양의 코드가 있으므로 완료 방법을 변경하는 것은 바람직하지 않습니다. 그렇다면 새로운 활동을 통해 화면의 내용을 인식해야 할 필요가 있습니다.새로운 활동의 콘텐츠보기 유지
새로운 활동 클래스를 만들 때 현재 findViewById (..)를 사용하는 화면에 있어야하는 것을 얻을 수없는 것 같습니다.
MainActivity.Java와 MapsActivity.java의 두 가지 활동이 있습니다. 이 인스턴스는 서로 동시에 실행됩니다. 지도 액티비티 파일을 짧게 포함 할 수 있습니다. 자세한 설명은 주석에 있습니다.
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_maps); <--This will change the content view, which is not what I want as I already have the content view set before this activity is called. But, if I allow this to run, then the subsequent code works since it's "aware" of the contents on the screen.
// Basically I need this activity to function as if I were to write
// setContentView(layout); (but not actually write it)
Button backBtn = (Button) findViewById(R.id.backBTN);
backBtn.setBackgroundColor(Color.RED); //This causes a null error because it cannot find backBtn since backBtn is in my previous activity. (But backBtn is on the screen at the point when this activity runs)
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this); //This is what I'm trying to make work, if I get the above functioning. This will work.
}
@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));
}
} MainActivity.Java의 어느 시점에서
, 나는 레이아웃 화면의 내용을 변경 - 된 setContentView (레이아웃). 그런 다음 MapsActivity.Java를 시작하는 새로운 의도를 만듭니다.
목표는 Google지도가있는 SlidingPaneLayout을 가지는 것입니다. 새로운 액티비티를 SlidingPaneLayout 내부에서 실행하고 싶습니다. 가까운,하지만 내 SupportMapFragment (또는 모든 요소) 현재 화면 (setContentView 내 MainActivity에서 호출 된 이후)보기에서 얻을 수 없기 때문에, 나는 그것을 작동하게 만들 수 없습니다.
아이디어가 있으십니까?
관련 - "이 활동이 시작되기 전에 이미 컨텐트보기가 설정되어 있습니다." 너? 방법? 액티비티가 실제로 생성되기 전에 언제든지'setContentView'를 호출 할 수 없습니다 ... –
글쎄, MapsActivity.java에 설정된 컨텐트 뷰가 없습니다. 그것은 오래 전에 만들어진 MainActivity.java에 설정되어 있습니다. MainActivity에서 다음과 같이 보입니다 : trackFunction() { setContentView (layout); .... createIntent(); <- MainActivity에서 setContentView를 설정 한 후 MainActivity에서 새 MapsActivity를 호출하는 함수입니다. } – user3720749
활동은 완전히 별개의 항목입니다. 'MainActivity'의'setContentView'는'MapsActivity'에 아무런 영향을 미치지 않습니다. –