我需要为我的项目使用 ActionBarSherlock,但在使用 ListView 时出现错误。我知道我需要扩展到 ListActivity,但我确信还有其他方法可以解决这个问题。下面是我的课。
public class ViewPagerAdapter extends FragmentPagerAdapter {
// Declare the number of ViewPager pages
final int PAGE_COUNT = 3;
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int arg0) {
switch (arg0) {
// Open Maths.java
case 0:
MathActivity maths = new MathActivity();
return maths;
// Open Units.java
case 1:
UnitsActivity units = new UnitsActivity();
return units;
// Open Physics.java
case 2:
PhysicsActivity physics = new PhysicsActivity();
return physics;
}
return null;
}
下面是我的 MathActivity 类,它扩展了 SherlockFragment。
public class MathActivity extends SherlockFragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.math_layout);
String[] mathList = new String[] {"Item 1", "Item 2", "Item 3", "Item 4"};
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mathList));
}