这是我的代码片段。当我在靠近我的点击片段上选择时,我只想在活动中显示地图。
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();
}