這裏是我的主:添加片段不工作
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