简体   繁体   English

Android - 语音搜索应用?

[英]Android - Voice search app?

I am trying to create a simple Google Glass app with the GDK. 我正在尝试使用GDK创建一个简单的Google Glass应用程序。 I have an activity that is started with a voice command. 我有一个以语音命令启动的活动。 After that you get the possibility to talk what you search for, lets say you search for "football". 在那之后你就有可能谈论你搜索的内容,让我们说你搜索“足球”。

What this activity (or immersions as the guide tells me it is called on Google Glass) does is to make a search in an API that returns JSON data. 这项活动(或指南中的沉浸式告诉我在Google Glass上调用它)的作用是在返回JSON数据的API中进行搜索。 Then I want to parse that data and present the result to the user in form of a bunch of static cards that you can scroll through. 然后我想解析这些数据,并以一堆可以滚动的静态卡的形式将结果呈现给用户。

All this is working, but I feel limited by the GDK that for static cards I am not able to set images other than images that are in the application from the start. 所有这一切都有效,但我觉得受GDK限制,对于静态卡,我无法从一开始就设置应用程序中的图像以外的图像。 I would love to be able to have static cards with custom layouts. 我希望能够拥有自定义布局的静态卡。 Is this even possible in the way I am doing it right now? 这是我现在正在做的方式吗?

People here tell me that it can be done, but I can´t really figure out how to. 这里的人告诉我它可以做到,但我真的无法弄清楚如何做到。 Since all I am encountering on the Google Glass page is documentation that sais that it cant be done. 由于我在Google Glass页面上遇到的所有内容都是文件,因此无法完成。

I would also want the functionality to bundle these static cards together as a result and pin them to the Timeline so that you dont need to search for the same thing twice. 我还希望功能将这些静态卡捆绑在一起,并将它们固定到时间轴,这样您就不需要两次搜索同一个东西。

Could someone please help me figure out if I am even on the right track or if this is just not possible at this time with the GDK. 有人可以帮我弄清楚我是否在正确的轨道上,或者目前GDK是不可能的。

Many thanks Joakim 非常感谢Joakim

Use a CardScrollView and create your own CardScrollAdapter in the getView function you inflate a layout from an xml file and fill in all information, like you would do in an android app. 使用CardScrollView并在getView函数中创建自己的CardScrollAdapter ,从xml文件中扩展布局并填写所有信息,就像在Android应用程序中一样。

Edit after reading comments: In your Adapter class add 阅读注释后编辑:在Adapter类中添加

public static class ViewHolder{
    public TextView text;
    public ImageView image;
}

And change 并改变

public View getView(int position, View convertView, ViewGroup parent) {
     return mCards.get(position).toView();
}

into

public View getView(int position, View convertView, ViewGroup parent) {
     ViewHolder holder;
     if(convertView==null) {
         convertView = inflater.inflate(R.layout.mycardlayout, null);
         holder = new ViewHolder();
         holder.text = (TextView) vi.findViewById(R.id.text);
         holder.image=(ImageView)vi.findViewById(R.id.image);
         convertView.setTag( holder );
     } else holder = (ViewHolder) convertView.getTag();

     myObject = getItem(position); //HERE YOU SHOULD MAKE SURE MYOBJECT IS THE CORRECT OBJECT

     holder.text.setText(myObject.getName());
     lazyLoad(holder.image, myObject.getImageUrl()); //USE LAZY LOADING LIBRARY
     return convertView;
}

So all you have to do: 所以你要做的就是:

  1. check if getItem is implemented in your Adapter 检查Adapter是否实现了getItem

  2. use lazyloading for the image (if a remote image, which looks like it will be) 对图像使用延迟加载(如果是远程图像,看起来会像这样)

  3. create the mycardlayout.xml file in the /layout folder which has to contain a TextField with the id text and an ImageView with the id image /layout文件夹中创建mycardlayout.xml文件,该文件必须包含带有id textTextField和带有id imageImageView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM