2017-01-11 17 views
-3

我試圖用這個video更換AppCompatActivity的片段,但不能訪問老班

創建BottomBar但是,我有一個現有的項目,除少數類已經實現了,當我試圖通過片段改變AppCompatActivity,我老方法/類是不可訪問

老班的excract:

public class ChoixFormulaire extends Fragment { 


    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

     View rootView=inflater.inflate(R.layout.activity_choix_formulaire,container,false); 

     return rootView; 
    } 

    public void formJ(View v){ 
     Intent i = new Intent(ChoixFormulaire.this,RechercheJournalier.class); 
     startActivity(i); 
    } 
    public void formP(View v){ 
     Intent i = new Intent(ChoixFormulaire.this,FormulaireRecherche.class); 
     startActivity(i); 
    } 
    public void retourF(View v){ 
     Intent i = new Intent(ChoixFormulaire.this,RechercheDuJour.class); 
     startActivity(i); 
    } 

但是,堡壘這一部分:

(ChoixFormulaire.this,RechercheJournalier.class); 
(ChoixFormulaire.this,FormulaireRecherche.class); 
(ChoixFormulaire.this,RechercheDuJour.class); 

我有這樣的錯誤:

"Cannot resolve constructor 'Intent(com.appli.cci.ports2a.Recherches.ChoixFormulaire, java.lang.Class<com.appli.cci.ports2a.Recherches.RecherchesJournalier>)' 
+0

你可以使用活動的情況下,打開新的活動。 –

回答

0

意圖需要與父活動或context.So您需要使用您的片段的家長活動上下文

Intent intent = new Intent(getActivity(),MyClass.class); 

你需要你通過應用程序創建從這樣的第一個活動排列: -

Bundle bundle=new Bundle(); 
bundle.putStringArray(key, new String[]{value1, value2}); 
Intent i=new Intent(context, Class); 
i.putExtras(bundle); 

你可以從其他活動獲得數組lik E本

Bundle bundle=this.getIntent().getExtras(); 
String[] array=bundle.getStringArray(key); 
+0

偉大的工作!但是,在一個類的其它我現在有: spinnerArray2 = mA.getSpinnerArray(); Csa = new CustomSpinnerAdapter(this,R.layout.content_spinner,spinnerArray2); spin2.setAdapter(Csa); idDefaultStr = mA.getIdSpin(); idDefault = Integer.parseInt(idDefaultStr)-1; 我在一個erreor: -mA.getSpinnerArray(); - mA.getiDSpin() 你知道爲什麼嗎? –

+0

那裏有什麼mA? –

+0

如果你已經在主要活動中定義了數組列表並試圖進入另一個列表,這不是獲得它的正確方法。 –

0
不使用情況下正確地檢查這個

public void formJ(View v){ 
      Intent i = new Intent(getActivity(),RechercheJournalier.class); 
      startActivity(i); 
     } 
+0

偉大的工作!但是,在一個類的其它我現在有: spinnerArray2 = mA.getSpinnerArray(); Csa = new CustomSpinnerAdapter(this,R.layout.content_spinner,spinnerArray2); spin2.setAdapter(Csa); idDefaultStr = mA.getIdSpin(); idDefault = Integer.parseInt(idDefaultStr)-1; 我有一個錯誤: -mA.getSpinnerArray(); - mA.getiDSpin() 您知道爲什麼嗎? –