Android列表视图

时间:2013-10-09 09:36:54

标签: android

我正在使用View寻呼机和寻呼机适配器进行用户滑动。我的要求是,我有三个列表视图,即0,1,2。首先我需要显示第一个列表视图,即索引位置1.当用户向左滑动时,我必须显示40%的0索引位置列表视图和60%的第二个索引位置1列表视图(在同一视图中),当用户向右滑动时,我必须显示50%的索引位置1列表视图和50%的索引位置2列表视图(在同一视图中)。在过去的几天里,我正在努力解决这个问题。请给我解决这个问题的解决方案。

我的代码是

private Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.activity_main);

    ListView listview1 = new ListView(mContext);
    ListView listview2 = new ListView(mContext);
    ListView listview3 = new ListView(mContext);

    Vector<View> pages = new Vector<View>();

    pages.add(listview1);
    pages.add(listview2);
    pages.add(listview3);

    ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
    CustomPagerAdapter adapter = new CustomPagerAdapter(mContext,pages);
    vp.setAdapter(adapter);
    vp.setCurrentItem(1);
     listview1.setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,new String[]{"A1","B1","C1","D1"}));
    listview2.setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,new String[]{"A2","B2","C2","D2"}));
    listview3.setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,new String[]{"A3","B3","C3","D3"}));
    }

CustomPagerAdapter

公共类CustomPagerAdapter扩展了PagerAdapter {

    private Context mContext;
    private Vector<View> pages;
    View page;
    int i=0;
    public CustomPagerAdapter(Context context, Vector<View> pages) {
         this.mContext=context;
         this.pages=pages;
    }
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
         page = pages.get(position);
            container.addView(page);
         Log.i("venkat2", "is" + position);
         //position=position * 2;
         return page;
    }
            @Override
    public int getCount() {
            return pages.size();
            }
            @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //Log.i("venkat3", "is" + "3");
         container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        //Log.i("venkat4", "is" + "4");
          return view.equals(object);
    }

谢谢&amp;问候, Venkatesan.R

0 个答案:

没有答案