2014-03-04 56 views
0

我嘗試用碎片的工作中,我創建BusModelActivity這種延伸ListFragment開放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