我想使用來自Androidhive的this sample使用ViewPager。但我不能在API 8中使用它直到10.我怎樣才能改變這個例子的這種情況?請幫幫我。在API中使用ViewPager 8-10 android
public class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(android.support.v4.app.FragmentManager fm) {
super(fm);
}
public int getCount() {
return 2;
}
public Fragment getItem(int i) {
switch (i) {
case 0:
return new One();
case 1:
return new Two();
}
return null;
}
}
,這是One.java: 和二的.java是一樣的。
public class One extends Fragment {
private MediaPlayer mediaPlayer;
@Override
public View onCreateView(LayoutInflater inflater
, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.one, container, false);
// BTN
assert rootView != null;
rootView.findViewById(R.id.one_soundBTN)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// play sound
mediaPlayer = MediaPlayer.create(getActivity(), R.raw.one);
mediaPlayer.start();
//show image
rootView.findViewById(R.id.one_image).setVisibility(View.VISIBLE);
}
});
return rootView;
}
}
問題是什麼標籤?你在哪裏得到一個錯誤? –