我尝试使用片段,我创建了BusModelActivity,例如扩展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);
}
}
但我无法从其他活动
导航到它Intent intent = new Intent(BusSearchParamActivity.this,BusModelsActivity.class);
startActivity(intent);
我明白了:
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?
但是当我尝试添加到AndroidManifest文件时它无法找到我的活动。如何从活动中运行ListFragment?
答案 0 :(得分:0)
看到您可以将片段附加到活动。
如: -
FragmentManager fm = getFragmentManager();
if (fm.findFragmentById(android.R.id.content) == null) {
BusModelsActivity list = new BusModelsActivity ();
fm.beginTransaction().add(android.R.id.content, list).commit();
}
然后导航如下: -
Intent intent = new Intent(BusSearchParamActivity.this,YourActivity.class);
startActivity(intent);
该活动应该出现在AndroidManifest.xml