简体   繁体   中英

Android - Voice search app?

I am trying to create a simple Google Glass app with the GDK. 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. 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. 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.

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.

Many thanks 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.

Edit after reading comments: In your Adapter class add

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

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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