我創建了三個片段以顯示在我的主要活動中。這是三個片段活動之一:如何在選項卡片段中添加列表視圖
public static class Fragment1 extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
String[] values=new String[]{"India", "java", "c++","Ad.Java", "Linux", "Unix"};
public Fragment1() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Create a new TextView and set its text to the fragment's section
// number argument value.
View v = inflater.inflate(R.layout.center, null);
return v;
}
}
我想在此片段中顯示listView。我試圖用內部onCreateView()
方法驗證碼:
ArrayAdapter<String> adapter=new ArrayAdapter<String>(Main.this,android.R.layout.simple_list_item_1,values);
setListAdapter(adapter);
,但它顯示的錯誤。如何做到這一點?
你試過ListFragment? – vandzi 2013-02-16 07:40:15