これは私のコードフラグメントです。タップ フラグメントで [近く] を選択したときに、アクティビティにマップを表示したいだけです。
public class MainActivity extends FragmentActivity {
Map m = new Map();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction transaction = fm
.beginTransaction();
Fragment startFragment = new ViewAll();
transaction.add(R.id.fragment_placeholder, startFragment);
transaction.commit();
}
public void onSelectFragment(View view) {
Fragment newFragment;
if (view == findViewById(R.id.btnNearMe)) {
newFragment = new NearMe();
} else if (view == findViewById(R.id.btnCategory)) {
newFragment = new Category();
} else if (view == findViewById(R.id.btnViewAll)) {
newFragment = new ViewAll();
} else if (view == findViewById(R.id.btnSignIn)) {
newFragment = new SignUpIn();
} else {
newFragment = new ViewAll();
}
android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.replace(R.id.fragment_placeholder, newFragment);
transaction.addToBackStack(null);
transaction.commit();
}