下面是我設置的fragment,我想改變fragment的格式。正常情況下我應該使用新的fragment創建一個新的activity,然後創建intent。現在是有一個activity有一些內容,我想只在一個地方更新。那麼我使用初始創建的activity,如何把一個fragment改變成另一個fragment?
view = inflater.inflate(R.layout.inst_fragment, container, false);
furnTextView = (TextView) view.findViewById(R.id.furn_textview);
archTextView = (TextView) view.findViewById(R.id.arch_textview);
furnTextView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(MotionEvent.ACTION_UP == event.getAction()){
openCatalog("furn");
}
return false;
}
});
archTextView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(MotionEvent.ACTION_UP == event.getAction()){
openCatalog("arch");
}
return false;
}
});
return view;
把你需要改變的那部分定義成fragmnet
FragmentTransaction transaction = getFragmentManager()
.beginTransaction()
transaction .replace(你的fragment)
transaction.commit();