我使用过自定义基础适配器。我想在列表中实现望远镜观察。我有一个无限的列表视图。
ArrayList<String> months=new ArrayList<>();
months.add("January");
months.add("February");
months.add("March");
months.add("April");
months.add("May");
months.add("June");
months.add("July");
months.add("August");
months.add("September");
months.add("October");
months.add("November");
months.add("December");
CircularListAdapter circularListAdapter=new CircularListAdapter(new CircularBaseAdapterDatePickerMonth(getActivity(),months));
monthList.setAdapter(circularListAdapter);
monthList.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == 0) {
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
int firstVisibleRow=monthList.getFirstVisiblePosition();
int lastVisibleRow=monthList.getLastVisiblePosition();
}
});
return view;
}
以上是我的主要代码 下面是我的适配器
/**
* Created by user4 on 07-05-2016.
*/
public class CircularBaseAdapterDatePickerMonth extends BaseAdapter {
Activity activity;
ArrayList<String> items;
public CircularBaseAdapterDatePickerMonth(Activity activity, ArrayList<String> items) {
this.activity = activity;
this.items = items;
}
@Override
public int getCount() {
return items.size();
}
@Override
public String getItem(int position) {
return items.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MyviewHolder myviewHolder;
if (convertView != null) {
myviewHolder = (MyviewHolder) convertView.getTag();
} else {
myviewHolder = new MyviewHolder();
convertView = activity.getLayoutInflater().inflate(R.layout.custom_date_picker_dialog_list_text, parent, false);
myviewHolder.textView = (TextView) convertView.findViewById(R.id.Onboarding_DateDialog_List_text);
convertView.setTag(myviewHolder);
}
myviewHolder.textView.setText(items.get(position));
return convertView;
}
static class MyviewHolder {
TextView textView;
}
}
我也不确定onScrollListener()
是否对我有帮助。