0

これが私のメインです:

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();

    }


}

私の 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);
    }
}

この問題は、数日前に発生した問題と非常によく似ていますが、そのソリューションをこのアプリケーションに適用していますが、まだ機能しません。

.addメッセージの下に赤い線が引かれていますThe method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, fragA)

別のサンプル アプリケーションでこのコードを記述しているため、これは悪化しています。見た目は同じですが、機能します。

4

1 に答える 1

5

うーん...クリーンを行い、R.javaを削除し、Eclipseを再起動しました。そして今、それは機能します。ああ少年。

于 2012-07-30T16:15:01.823 に答える