[英]Google Glass GDK - CardScrollAdapter getHomePosition not working
In the official GDK documentation for the CardScrollAdapter ( link ) it states that you can override public int getHomePosition()
to have your adapter define a new "home" position (aka: The view that is initially displayed when the parent CardScrollView is displayed/activated). 在CardScrollAdapter的官方GDK文档( 链接 )中,它声明您可以重写
public int getHomePosition()
以使适配器定义一个新的“主”位置(aka:显示/激活父CardScrollView时最初显示的视图) )。 The problem is... I've attempted to do this but public int getHomePosition()
never appears to be called by the adapter. 问题是...我试图这样做,但是
public int getHomePosition()
似乎从未被适配器调用。
Here is a simplified example... 这是一个简化的示例...
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);
}
}
When I initialize and assign this adapter to a CardScrollView and then activate()
it, the first card displayed is "Position: 0". 当我初始化该适配器并将其分配给CardScrollView然后
activate()
时,显示的第一张卡为“位置:0”。
My question is, am I using getHomePosition()
incorrectly or does it simply not work as expected in the latest Glass Development Kit Preview release? 我的问题是,我
getHomePosition()
错误地使用了getHomePosition()
或者它根本无法按最新的Glass Development Kit Preview版本所期望的那样工作?
I haven't actually used getHomePosition()
, but I have gotten the same functionality you are describing by using mCardScrollView.setSelection(homePosition)
right after setting the content view. 我实际上没有使用过
getHomePosition()
,但是在设置内容视图之后,我已经通过使用mCardScrollView.setSelection(homePosition)
获得了与您描述的功能相同的功能。 If you haven't gotten this working by now, this might help. 如果您现在还没有开始工作,这可能会有所帮助。
EDIT: After looking through the docs, I think they meant the overridden function to be used like this: 编辑:浏览文档后,我认为它们的意思是要像这样使用重写的函数:
mCardScrollView.setSelection(getHomePosition())
Otherwise it would make more sense to call it setHomePosition()
否则,将其称为
setHomePosition()
会更有意义
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.