是否可以在listview中将水平滑动viewpager作为listitem。

时间:2014-05-31 13:51:06

标签: android xml listview android-fragments android-listview

我一直在尝试将水平滑动viewpager作为listview中的项目。但我没有那样做。我没有得到任何编译错误,但我得到运行时。 我想知道这有可能吗?如果没有请告诉我替代解决方案???

这里是listview适配器

package com.example.infogamma;

public class CustomSwipeItem extends ArrayAdapter<String>  {

Context context;
CollectionDemoActivity cda;

public CustomSwipeItem(Context context, int resourceId,
        List<String> items) {
    super(context, resourceId, items);
    this.context = context;
}

/*private view holder class*/
private class ViewHolder {
    ViewPager vp;

}

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    String rowItem = getItem(position);
    cda = new CollectionDemoActivity();




    LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.swipe_item, null);
        holder = new ViewHolder();

        holder.vp = (ViewPager) convertView.findViewById(R.id.pager);
        convertView.setTag(holder);
    } else 
        holder = (ViewHolder) convertView.getTag();


    holder.vp.setAdapter(cda.getViewPager());



    return convertView;
}
}

这是我的viewpage适配器

public class CollectionDemoActivity extends FragmentActivity {

/**
 * The {@link android.support.v4.view.PagerAdapter} that will provide fragments representing
 * each object in a collection. We use a {@link android.support.v4.app.FragmentStatePagerAdapter}
 * derivative, which will destroy and re-create fragments as needed, saving and restoring their
 * state in the process. This is important to conserve memory and is a best practice when
 * allowing navigation between objects in a potentially large collection.
 */
DemoCollectionPagerAdapter mDemoCollectionPagerAdapter;

static String[] screens= {"makescr1","makescr2","makescr3"};

/**
 * The {@link android.support.v4.view.ViewPager} that will display the object collection.
 */
ViewPager mViewPager;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.full_image);


    // Create an adapter that when requested, will return a fragment representing an object in
    // the collection.
    // 
    // ViewPager and its adapters use support library fragments, so we must use
    // getSupportFragmentManager.
    mDemoCollectionPagerAdapter = new DemoCollectionPagerAdapter(getSupportFragmentManager());

    // Set up action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home button should show an "Up" caret, indicating that touching the
    // button will take the user one step up in the application's hierarchy.
    actionBar.hide();

    // Set up the ViewPager, attaching the adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setRotation(90);
    mViewPager.setAdapter(mDemoCollectionPagerAdapter);
   // mViewPager.canScrollVertically(View.FOCUS_DOWN);


}

public DemoCollectionPagerAdapter getViewPager()
{


//  ViewPager v = (ViewPager) inflater.inflate(R.id.pager1,null);
    //super.onCreate(savedInstanceState);
    mDemoCollectionPagerAdapter = new      DemoCollectionPagerAdapter(getSupportFragmentManager());

   // mViewPager = new ViewPager(this);

    //v.setAdapter(mDemoCollectionPagerAdapter);

    return mDemoCollectionPagerAdapter ;

}
/*

0 个答案:

没有答案