Pergunta

I try to work with fragments, I create BusModelActivity such extends ListFragment

public class BusModelsActivity extends ListFragment {

String data [] = new String[]{"1","2","3","4"};

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ArrayAdapter<String> adapter =  new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,data);
    setListAdapter(adapter);
}

}

but I can't navigate to it from other activity

Intent intent = new Intent(BusSearchParamActivity.this,BusModelsActivity.class);
startActivity(intent);

I get:

android.content.ActivityNotFoundException: Unable to find explicit activity class {ru.avtobus66.finder_transport/ru.avtobus66.finder_transport.BusModelsActivity};
have you declared this activity in your AndroidManifest.xml?

but when I try to add to AndroidManifest file It can't find my activity. How to run ListFragment from activity?

Nenhuma solução correta

Outras dicas

see you can attach a fragment to an activity.

like as :-

FragmentManager fm = getFragmentManager();  

  if (fm.findFragmentById(android.R.id.content) == null) {  
   BusModelsActivity list = new BusModelsActivity ();  
   fm.beginTransaction().add(android.R.id.content, list).commit();  
  }

And then after navigate like as follows:-

Intent intent = new Intent(BusSearchParamActivity.this,YourActivity.class);
startActivity(intent);

and that activity should be present in the AndroidManifest.xml

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top