I am doing a slide view , and by mistake I have added the pageview and ViewPager in same xml and that caused problems , when I tried to fix it the slide stoped working , so I need help to make the slide working.( In this tutorials 1 and 2 explained the viewpage should be in another xml but honestly I didnt understand why .
This is SingleViewActivity.java
public class SingleViewActivity extends Activity {
private ImageView image1;
ViewPager viewPager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_view);
//
slide mCustomPagerAdapter = new slide(this);
viewPager = (ViewPager) findViewById(R.id.viewPager);
viewPager.setAdapter(mCustomPagerAdapter);
}}
and this is slide.java
public class slide extends PagerAdapter{
Context mContext;
LayoutInflater mLayoutInflater;
public slide(Context context) {
mContext = context;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mThumbIds.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((LinearLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View itemView = mLayoutInflater.inflate(R.layout.activity_main, container, false);
ImageView imageView = (ImageView) itemView.findViewById(R.id.SingleView);
imageView.setImageResource(mThumbIds[position]);
container.addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout) object);
}
public Integer[] mThumbIds =
{
R.drawable.sample2,
R.drawable.sample2,
R.drawable.sample2,
R.drawable.sample2,
R.drawable.sample2,
R.drawable.sample2,
R.drawable.sample2,
R.drawable.sample2
};
}
Single view.xml
<ImageView android:id="@+id/SingleView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/edittextm"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
As I understand view pager should be in another xml , please note that I want the images to slide in SingleViewactivity.
Aucun commentaire:
Enregistrer un commentaire