我正在尝试这个教程https://www.youtube.com/watch?v=id46JCY76f0。已逐字逐句地跟着它,但已经到了16:00进入视频,这个特殊的代码给我一个不兼容的类型错误:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentManager;
public class MyAdapter extends FragmentPagerAdapter {
final int pageCount=3;
Bundle info;
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int pos) {
info= new Bundle();
switch (pos){
case 0;
Asia asia = new Asia();
info.putInt("currentPager", pos++);
asia.setArguments(info);
return asia;
case 1;
Africa africa = new Africa();
info.putInt("currentPager", pos++);
africa.setArguments(info);
return africa;
case 2;
Europe eu = new Europe();
info.putInt("currentPager", pos++);
eu.setArguments(info);
return eu;
}
return null;
}
@Override
public int getCount() {
return 0;
}
}
错误:
必需的android.support.v4.app.Fragment 找到com.example.petakirikiri.swipetabs.Asia
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Asia extends ListFragment{
String[] countries = {"India", "Pakistan", "Malaysia", "Bangladesh", "Singapore"};
ArrayAdapter<String> adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
adapter =new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple_choice, countries);
setListAdapter(adapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onStart() {
super.onStart();
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
}
答案 0 :(得分:0)
您是否通过片段扩展亚洲? 此外,在这种情况下,片段必须匹配 - 即有两种类型:
android.support.v4.app.Fragment
和
android.app.Fragment;
如果它们不相同,则会出现类型不匹配错误。