EGH*_*HDK 0 java android android-fragments
这是我的主要内容:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我的FragA课程:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
这个问题与我几天前遇到的问题非常相似,但是我正在将这个解决方案应用到这个应用程序中,但仍然无法让它工作.
我得到一条红线.add
,上面写着消息说The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, fragA)
这是加重的,因为在另一个示例应用程序中,我编写了此代码.看起来相同,但它的工作原理!
嗯......我刚刚做了一个干净的,删除了我的R.java并重新启动了eclipse.现在它有效.好家伙.
归档时间: |
|
查看次数: |
2807 次 |
最近记录: |