我有一个listview,例如:黄色标记在第110位。如何从第110个位置显示为列表视图的起始位置。因为用户需要滚动才能看到在第110个位置标记为黄色的黄色。
这是代码。
public class TableOfContentsListAdapter extends BaseAdapter {
@Override
public final View getView(final int position, View convertView, final ViewGroup parent) {
int type = getItemViewType(position);
if ((convertView == null) || (((Integer) convertView.getTag()) != type)) {
convertView = createView(position);
convertView.setTag(type);
}
final BaseTableOfContents node = getItem(position);
tocView = (Node) convertView;
((Checkable) convertView).setChecked(okayToHighlightAnchorNode(node, position));
convertView.setActivated(okayToHighlightTouchNodes(node, position));
return convertView;
}
}
public boolean okayToHighlightTouchNodes(BaseTableOfContents candidate, int position) {
return mTouchNodePedigree.indexOf(candidate.getNodeId()) >= position;
}
MainActivity: (I am clueless how to use it to display.)
//returnValue is the object of listview.
returnValue.getListView().setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int position) {
TableOfContentsListAdapter adapter = (TableOfContentsListAdapter) absListView.getAdapter();
Log.v("scrolling","scrolling");
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log.v("visibleItemCount","visibleItemCount"+visibleItemCount);
Log.v("visibleItemCounts","visibleItemCounts"+totalItemCount);
}
});
此外,列表仅显示0到9,滚动时显示10到20,再次滚动20到30,依此类推。因此,我无法使用高亮的黄色标记来显示处于其他位置的标记。
答案 0 :(得分:0)
如果可以的话,我建议您使用RecyclerView而不是ListView。它提供了类似以下方法的独特功能:public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseHttpSys(options => {
options.Authentication.Schemes =
AuthenticationSchemes.NTLM | AuthenticationSchemes.Negotiate;
options.Authentication.AllowAnonymous = false;
})
.Build();
在这种情况下可以为您提供帮助。顺便说一句,它比ListView更有效地利用资源。