Im trying to make an image slider, but the imageview is not appearing when running on the emulator, I tried on another project and it runs perfectly. I tried changing the id of the imageView and it seems to be working fine, but nothing is showing when I run the app. at the bottom there is my xml file
Adapter class:
public class CustomSwipeAdapter extends PagerAdapter {
private int[] image_resources = {R.drawable.mario, R.drawable.dice, R.drawable.camera};
private Context ctx;
private LayoutInflater layoutInflater;
public CustomSwipeAdapter(Context ctx){
this.ctx =ctx;
}
@Override
public int getCount() {
return ScrollingActivity.image.size();
}
@Override
public boolean isViewFromObject(View view, Object o) {
return (view ==(NestedScrollView)o);
}
@Override
public Object instantiateItem(ViewGroup container, int position){
layoutInflater = (LayoutInflater)ctx.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View item_view = layoutInflater.inflate( R.layout.swipe_layout, container, false );
ImageView imageView = (ImageView) item_view.findViewById( R.id.img);
imageView.setImageResource( image_resources[position] );
container.addView( item_view );
return item_view;
}
@Override
public void destroyItem (ViewGroup container, int position, Object object){
container.removeView( (NestedScrollView)object );
}
}
Activity class:
public class ItemsDetailsActivity extends AppCompatActivity {
ViewPager viewPager;
CustomSwipeAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_items_details );
viewPager = findViewById( R.id.view_pager );
adapter = new CustomSwipeAdapter( this );
viewPager.setAdapter( adapter );
}
}
Layout file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout
android:id="@+id/testLay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="276dp"
android:layout_marginTop="25dp"
android:layout_weight="1"
android:visibility="visible" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>