我创建了三个片段来展示我的主要活动。这是三个片段活动之一:
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);
但它显示错误..如何做到这一点?