这里是我的主:添加片段不工作
package com.example.frags;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
public class NewMessage extends FragmentActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.new_message);
//Set new fragment
FragA fragA = new FragA();
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.add(R.id.container_id, fragA);
transaction.commit();
}
}
我弗拉加类:
package com.example.frags;
import android.os.Bundle;
import android.text.style.SuperscriptSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class FragA extends android.support.v4.app.Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.choose_pill_frag, container, false);
}
}
这个问题是非常相似的一个问题,我有一个few days ago,但我认为申请这个应用程序的解决方案,我仍然无法得到它的工作。
我收到一条红线.add
根据与消息说The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, fragA)
这加重,因为在另一个示例应用程序我有this code写的。看起来相同,但它的工作原理!
发布你的'FragA'类,我敢打赌,你忘了导入'android.support.v4.app.Fragment;'在里面 – Barak 2012-07-29 16:05:14