Here is my main:
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();
}
}
My FragA class:
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);
}
}
This problem is very similar to a problem I had a few days ago, but I'm applying that solution to this application and I still can't get it to work.
I'm getting a red line under .add
with the message saying The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, fragA)
This is aggravating because in another sample application I have this code written. Which looks identical, but it works!