在我的项目中,listview 包含用于加载图像的 viewpager。实际上,这个 listview 是在一个使用滑动菜单的片段中加载的。
这里的问题是布局既没有加载也没有显示任何错误。
我使用了这样的页面容器 s://gist.github.com/devunwired/8cbe094bb7a783e37ad1
我的适配器类
public class SampleAdapter extends BaseAdapter {
private Activity activity;
private String[] titleData;
private int[] imageData;
private ArrayList<Request> List;
PagerContainer mContainer;
MyPagerAdapter adapter;
public SampleAdapter(Activity a, ArrayList<Request> list) {
activity = a;
List = new ArrayList<Request>();
List = list;
}
@Override
public int getCount() {
return List.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.cus_hub_list, parent, false);
mContainer = (PagerContainer) rowView.findViewById(R.id.pager_container);
ViewPager pager = mContainer.getViewPager();
adapter = new MyPagerAdapter();
pager.setAdapter(adapter);
pager.setOffscreenPageLimit(adapter.getCount());
pager.setPageMargin(15);
pager.setClipChildren(false);
return rowView;
}
public class MyPagerAdapter extends PagerAdapter {
@Override
public Object instantiateItem(ViewGroup container, int position)
{
TextView view = new TextView(activity);
view.setText("Item " + position);
view.setGravity(Gravity.CENTER);
view.setBackgroundColor(Color.argb(255, position * 50,
position * 10, position * 50));
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public int getCount() {
return 5;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return (view == object);
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
}
}
但问题是 listview 没有显示任何列表项。
任何人都可以找出问题所在。
提前致谢。