快速实现美团首页切换效果
public class MyViewPagerAdapter extends RVAdapter<MenuItemEntity> {
public MyViewPagerAdapter(Context mContext, List<MenuItemEntity> dataList, int pageSize, int spanCount) {
super(mContext, dataList, pageSize, spanCount);
}
@Override
protected int getLayoutId() {
return R.layout.dot_view_pager_item;
}
@Override
protected void onBindView(RecyclerViewHolder holder, int position, MenuItemEntity data) {
TextView tv = holder.getView(R.id.tv);
tv.setText(data.getTitle());
tv.setCompoundDrawablesWithIntrinsicBounds(0, data.getResId(), 0, 0);
}
}
mViewPager.setAdapter(adapter);
adapter.setOnItemClickListener(new RVAdapter.OnItemClickListener<MenuItemEntity>() {
@Override
public void onItemClick(RecyclerViewHolder holder, int position, MenuItemEntity data) {
Toast.makeText(MainActivity.this, position + "-->" + data.getTitle(), Toast.LENGTH_SHORT).show();
}
});
}
Copyright (C) 2016 [email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.