私は、FrameLayoutを含むxmlファイルeditor.xmlを作成しました。私の主な活動では、自分のカスタムフラグメントをFrameLayoutに追加しようとしています。フラグメントコンテナにフラグメントを追加しようとしていますFrameLayout
私のフラグメントを追加しようとしたとき、私は受信エラーがある:
メソッドは、型FragmentTransactionに(int型、フラグメント)を追加の引数には適用されません(INT、editorFrag)
しかし、私のeditorFrag私はなぜこれが起こっているのか混乱しているので、断片を拡張します。以下は、私が言及したファイルのための私のコードです。どんな助けもありがとうございます。 Luksprogが私を伝えることで、以下の私のために、この問題に答え
:回答
Editor.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
editorFrag.java
public class editorFrag extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
// Inflate the layout for this fragment
return inflater.inflate(R.layout.newlevel, container, false);
}
}
MainActivity.java
public class editorActivity extends FragmentActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.editor);
// Check that the activity is using the layout version with the fragment_container FrameLayout
if(findViewById(R.id.fragment_container) != null)
{
// if we are being restored from a previous state, then we dont need to do anything and should
// return or else we could end up with overlapping fragments.
if(savedInstanceState != null)
return;
// Create an instance of editorFrag
editorFrag firstFrag = new editorFrag();
// add fragment to the fragment container layout
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, firstFrag);
}
}
}
〜にc私の輸入品をどうぞ。 Eclipseは、必要なサポートバージョンではなく、SDKバージョンのFragmentをインポートすることを選択しました。お手伝いありがとう。
のような)(コミット追加輸入を確認してください。互換性パッケージ 'Fragment'の代わりに' Fragment'の 'SDK'バージョンをインポートしていないか確認してください。 – Luksprog
あなたは正しいです、私は私のためにeclipseのインポートをさせて、それは実際に私の活動でサポートバージョンを選択したSDKのバージョンを選択しました。ありがとうございます – Pedrom
@Perdomの心はこの質問の答えを受け入れていますか?ありがとう。 http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work –