尝试使用Fragment
加载Gingerbread
android.support.v4.app
,但我一直收到以下错误:
The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, Welcome)
我的欢迎课延伸片段,不知道我在这里做错了什么?
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadfrag();
}
private void loadfrag() {
Welcome frag = new Welcome();
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.flactivity_main, frag); **<--- line with error**
transaction.commit();
}
}
import android.support.v4.app.Fragment;
public class Welcome extends Fragment{
private final String TAG = this.getClass().getSimpleName();
private ViewGroup mrootview;
private Activity mactivity;
private Context mcontext;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
//mrootview = (ViewGroup)
return inflater.inflate(R.layout.welcome, container, false);
}
}
答案 0 :(得分:3)
而不是getFragmentManager()
方法使用getSupportFragmentManager()
。