2017-08-05 9 views
0

をフラグメントに変換することはできません私は断片エラー:(26、24)エラー:互換性のない型:クラスは

を通じて、私は断片から延びる送信していたすべてのクラスをアンドロイドのメニューアプリをやろうとしているとそれは私に求めているアレイの断片ですが、まだそうではないと言います。

enter image description here

import android.app.Fragment; 
import android.app.FragmentManager; 
import android.app.FragmentTransaction; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 

public class Actividades extends AppCompatActivity implements InterfaceMenu { 

    //Array para menu y fragments 

    Fragment[] array_frag; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_actividades); 

     //Obtener del menu el boton pulsado 
     Bundle extras=getIntent().getExtras(); 
     menu(extras.getInt("BotonPulsado")); 


     array_frag = new Fragment[3]; 
     array_frag[0]= new Lintern(); 
     array_frag[1]= new Nivel(); 
     array_frag[2]= new Service(); 
    } 


    @Override 
    public void menu(int frag_boton) { 

     //obtener fragmentmanager y empezar transaccion 
     FragmentManager mimanager = getFragmentManager(); 
     FragmentTransaction mitransaction = mimanager.beginTransaction(); 
     //mandamos el id de donde se van a 
     // cargar los fragments y que fragment vamos a mandar 
     mitransaction.replace(R.id.actividades,array_frag[frag_boton]); 
     mitransaction.commit(); 
    } 
} 

ここでは、ちょうどこの

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 


/** 
* A simple {@link Fragment} subclass. 
*/ 
public class Lintern extends Fragment { 


    public Lintern() { 
     // Required empty public constructor 
    } 


    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     return inflater.inflate(R.layout.fragment_lintern, container, false); 
    } 

} 

答えて

1

のような彼らはすべて空になっている私のクラスの一つの問題は、あなたがgetFragmentManager()android.support.v4.app.Fragmentを使用することができない、ということであるのです。代わりにgetSupportFragmentManager()を使用する必要があります。

リンク:https://stackoverflow.com/a/20237647/3758972

+0

は、私はそこが、それでも私はuはそれが –

+0

[OK]を私はなく、画像を変更することはできませんエラーからの画像を確認することができないだろうように動作していないものを試してみました!エラーは "Imcompatible types"と表示されます。必須:adroid.app.Fragment –

+0

「v4.Fragment'ではなく、 'getFragmentManager()」の代わりに' android.app.Fragment'を使用する必要があります –

関連する問題