FragmentPagerAdapter - 不兼容的类型
FragmentPagerAdapter - Incompatible Types
正在尝试本教程 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);
}
}
你们在用 Fragment 扩展亚洲吗?
此外,在这种情况下,片段必须匹配 - 即有两种类型:
android.support.v4.app.Fragment
和
android.app.Fragment;
如果它们不相同,您将收到类型不匹配错误。
正在尝试本教程 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);
}
}
你们在用 Fragment 扩展亚洲吗? 此外,在这种情况下,片段必须匹配 - 即有两种类型:
android.support.v4.app.Fragment
和
android.app.Fragment;
如果它们不相同,您将收到类型不匹配错误。