Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DeepakJOct opened this issue Jun 26, 2019 · 7 comments

Comments

@DeepakJOct
Copy link

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.

@demoNo
Copy link
Owner

demoNo commented Jun 26, 2019

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;
    }
}

@DeepakJOct
Copy link
Author

DeepakJOct commented Jun 26, 2019

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
Copy link
Author

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.

@demoNo
Copy link
Owner

demoNo commented Jun 26, 2019

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());

@DeepakJOct
Copy link
Author

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.

@demoNo
Copy link
Owner

demoNo commented Jun 26, 2019

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

@DeepakJOct
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants