AutoScrollViewPager icon indicating copy to clipboard operation
AutoScrollViewPager copied to clipboard

Only limited scroll items. The viewpager is not taking more than 3 banners out of 7.

Open DeepakJOct opened this issue 6 years ago • 7 comments

I have cloned the repository into my IDE, used it as per the instructions in my custom project. The pager is working as expected but, it is taking only 3 pages by default. I have 7 pages out of which first two will scroll one by one and then the pager directly jumps to the last page.

I had tried to make it a custom implementation but was unable to find the exact line where this is going on. Let me know if there is any scope of implementation of this kind.

DeepakJOct avatar Jun 26 '19 09:06 DeepakJOct

I haven't limit the scroll items, you should implement viewpager adapter like this.

public class MyAdapter extends InfinitePagerAdapter {

    private List<String> data;

    public MyAdapter(List<String> data) {
        this.data = data;
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup container) {
        return your view;
    }
}

demoNo avatar Jun 26 '19 10:06 demoNo

This is my adapter,

public class MyAdapter extends InfinitePagerAdapter {

private List<String> data;
private LayoutInflater layoutInflater;
Context context;

public MyAdapter(List<String> data, Context context) {
    this.data = data;
    this.context = context;
    layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getItemCount() {
    return data == null ? 0 : data.size();
}


@Override
public View getItemView(int position, View convertView, ViewGroup container) {

    if (convertView == null) {
        //We must create a View:
        convertView = layoutInflater.inflate(R.layout.item_view, container, false);
        final TextView tv = convertView.findViewById(R.id.textView);
        tv.setText(data.get(position).trim());
    }
    //Here we can do changes to the convertView, such as set a text on a TextView
    //or an image on an ImageView.
    return convertView;
  }

}

This is my Main Activity

public class MainActivity extends AppCompatActivity {
AutoScrollViewPager mViewPager;
List<String> data;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    data = new ArrayList<>();
    data.add("ABCD");
    data.add("EFGH");
    data.add("HIJK");
    data.add("LMNO");
    data.add("PQRS");
    data.add("TUVW");
    data.add("XYZ");
    AutoScrollViewPager mViewPager = findViewById(R.id.viewPager);
    MyAdapter mAdapter = new MyAdapter(data, MainActivity.this);
    mViewPager.setAdapter(mAdapter);

    // optional start auto scroll
    mViewPager.startAutoScroll();
  }
}

Output:

ezgif com-crop

DeepakJOct avatar Jun 26 '19 10:06 DeepakJOct

The viewpager is infinite, but it is able to show only 3 positions of the list. 0, 1 and the last position.

Is there anything at any point that I need to modify to get all my banners into this viewpager.

DeepakJOct avatar Jun 26 '19 10:06 DeepakJOct

if (convertView == null) {
        //We must create a View:
        convertView = layoutInflater.inflate(R.layout.item_view, container, false);    
    }
final TextView tv = convertView.findViewById(R.id.textView);
        tv.setText(data.get(position).trim());

demoNo avatar Jun 26 '19 10:06 demoNo

This is working. Appreciate for that.

Is onPageClickListener is implemented in this library?? I am asking because I didn't find any methods saying so inside AutoScrollViewPager.java.

Can we implement it by making a custom ViewPager using this library. Suggestions will be helpful. Thank you.

DeepakJOct avatar Jun 26 '19 11:06 DeepakJOct

if (convertView == null) {
        //We must create a View:
        convertView = layoutInflater.inflate(R.layout.item_view, container, false);    
    }
convertView.setOnClickListener(...);

demoNo avatar Jun 26 '19 11:06 demoNo

Ok, thank you so much. I want to also add indicators onto the project and implement the whole module into the app. I hope it will work. I'll keep posting.

DeepakJOct avatar Jun 26 '19 11:06 DeepakJOct