gpt4 book ai didi

android - 在谷歌眼镜中显示菜单

转载 作者:行者123 更新时间:2023-11-29 16:02:52 26 4
gpt4 key购买 nike

您好,我在沉浸式学习中在普通卡片上创建菜单时遇到了问题。这是我目前所拥有的:

我有一个像这样实现 OnItemClickListener 的 CardScrollAdapter:

私有(private)类 ExampleCardScrollAdapter 扩展 CardScrollAdapter 实现 OnItemClickListener {

    @Override
public int findIdPosition(Object id) {
return -1;
}

@Override
public int findItemPosition(Object item) {
return mCards.indexOf(item);
}

@Override
public int getCount() {
return mCards.size();
}

@Override
public Object getItem(int position) {
return mCards.get(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

View rowView = convertView;
ViewHolder holder;

if(rowView==null) {
rowView = mInflater.inflate(R.layout.card_layout, null);
holder = new ViewHolder();
holder.mainText = (TextView) rowView.findViewById(R.id.tvMainText);
holder.fullImage = (ImageView) rowView.findViewById(R.id.fullImage);
holder.image1=(ImageView) rowView.findViewById(R.id.ivImage1);
holder.image2 = (ImageView) rowView.findViewById(R.id.ivImage2);
holder.image3 = (ImageView) rowView.findViewById(R.id.ivImage3);
holder.llImages = (LinearLayout) rowView.findViewById(R.id.llImages);
holder.llSecondaryImages = (LinearLayout) rowView.findViewById(R.id.llSecondaryImages);
rowView.setTag( holder );
} else holder = (ViewHolder) convertView.getTag();

CustomCard myObject = (CustomCard) getItem(position);

if (myObject.getCompanyInfo()!=null) {

System.out.println(myObject.getImageURL());
System.out.println(myObject.getCompanyInfo());

holder.mainText.setText(myObject.getCompanyInfo());
imageLoader.DisplayImage(myObject.getImageURL(), holder.image1);

holder.mainText.setVisibility(ImageView.VISIBLE);
holder.llImages.setVisibility(ImageView.VISIBLE);
holder.image1.setVisibility(ImageView.VISIBLE);

} else {
imageLoader.DisplayImage(myObject.getImageURL(), holder.fullImage);
holder.llImages.setVisibility(ImageView.VISIBLE);
holder.fullImage.setVisibility(ImageView.VISIBLE);
}

holder.image2.setVisibility(ImageView.GONE);
holder.image3.setVisibility(ImageView.GONE);
holder.llSecondaryImages.setVisibility(ImageView.GONE);

return rowView;
}

public class ViewHolder {
public TextView mainText;
public ImageView fullImage;
public ImageView image1;
public ImageView image2;
public ImageView image3;
public LinearLayout llImages;
public LinearLayout llSecondaryImages;
}

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.out.println("Click" + position);
onCreateOptionsMenu(null);

}

}

当我点击我的卡片时,它会打印“点击”和卡片的位置,这样就可以了。

之后,我想运行如下所示的 onCreateOptionsMenu:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.card_menu, menu);
return true;
}

我遇到的问题是了解如何使 onCreateOptionsMenu 运行?我必须从 onItemClick 方法而不是 null 提供的 Menu 菜单是什么?

//乔金姆

最佳答案

对于这种情况,您不需要单独的 Activity — 只有在需要显示 Activity 卡片中的菜单时才应该这样做。

错误出在您原来的 onItemClick 方法中:您应该调用 openOptionsMenu 来显示菜单,而不是 onCreateOptionsMenu

关于android - 在谷歌眼镜中显示菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22223727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com