[英]Google Glass GDK - CardScrollAdapter getHomePosition not working
在CardScrollAdapter的官方GDK文档( 链接 )中,它声明您可以重写public int getHomePosition()
以使适配器定义一个新的“主”位置(aka:显示/激活父CardScrollView时最初显示的视图) )。 问题是...我试图这样做,但是public int getHomePosition()
似乎从未被适配器调用。
这是一个简化的示例...
public abstract class StackOverflowExample extends CardScrollAdapter
{
private Context m_context = null;
public StackOverflowExample(Context context)
{
super();
m_context = context;
}
@Override public final int getCount()
{
return 3;
}
@Override public int getHomePosition()
{
return 1;
}
// Other misc adapter overrides here...
@Override public View getView(int position, View view, ViewGroup parent)
{
Card glassCard = new Card(m_context);
glassCard.setText("Position: " + position);
return glassCard.getView(view, parent);
}
}
当我初始化该适配器并将其分配给CardScrollView然后activate()
时,显示的第一张卡为“位置:0”。
我的问题是,我getHomePosition()
错误地使用了getHomePosition()
或者它根本无法按最新的Glass Development Kit Preview版本所期望的那样工作?
我实际上没有使用过getHomePosition()
,但是在设置内容视图之后,我已经通过使用mCardScrollView.setSelection(homePosition)
获得了与您描述的功能相同的功能。 如果您现在还没有开始工作,这可能会有所帮助。
编辑:浏览文档后,我认为它们的意思是要像这样使用重写的函数:
mCardScrollView.setSelection(getHomePosition())
否则,将其称为setHomePosition()
会更有意义
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.