当我点击图库项目时,我想更改视图寻呼机项目,但是当我在下面执行代码时,没有按照预期发生任何事情。
我已阅读了很多stackoverflow ans并基于此实现但没有运气
查看寻呼机
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/gallery"
/>
廊
<Gallery
android:layout_below="@id/top"
android:id="@+id/gallery"
android:spacing="20dp"
android:background="#000075"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</Gallery>
newGalleryAdapter =new newGalleryAdapter(MainActivity.this, arrCatName,arrCatBool);
gallery.setAdapter(newGalleryAdapter);
gallery.setSelection(0);
寻呼机适配器
pager = (ViewPager) findViewById(R.id.pager);
pager.setOffscreenPageLimit(arrCatId.size());
for (int j = 0; j < arrCatId.size(); j++) {
finalcontentpaths.add(arrCatId.get(j));
}
listProductItemAdapter= new MyPagerAdapter(MainActivity.this, finalcontentpaths);
pager.setAdapter(listProductItemAdapter);
listProductItemAdapter.notifyDataSetChanged();
pager.setCurrentItem(0);
图库项目点击
gallery.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
setPosition(position,save);
newGalleryAdapter.notifyDataSetChanged();
gallery.setSelection(position);
save = position;
//int a=pager.getCurrentItem()+1;
pager.setCurrentItem(position,false);
pager.setCurrentItem(position,true);
pager.setCurrentItem(position);
}
});
答案 0 :(得分:0)
这可能对你有用。
Xml
希望它会对你有所帮助。