3

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

Naveen
  • 1,948
  • 4
  • 17
  • 21
Jokez80
  • 131
  • 7

1 Answers1

3

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

Ferdau
  • 1,524
  • 1
  • 12
  • 21
  • I alrady have a CardScrollAdapter and a getView function. All it does right now is: public View getView(int position, View convertView, ViewGroup parent) { return mCards.get(position).toView(); } Sadly I am a real n00b at doing Android applications. Do you have any example? – Jokez80 Mar 05 '14 at 10:19
  • I also guess that I then need some sort of CustomCard class that extends Cards to set the data I want to add to the layout, am I right? – Jokez80 Mar 05 '14 at 10:25
  • Thanks! This worked splendid! Now I just want to take these cards and bundle them and place on the timeline. Is that possible? – Jokez80 Mar 05 '14 at 13:22
  • I see almost all your questions are about the same app, you cannot hope StackOverflow will help you with all your problems and give you all the code, because you are "a real n00b at doing Android applications", Google Glass IS android, so try to learn and understand android. This is the only way to become better than a beginner, with copy pasting and asking every problem over here, you will get nowhere. Sorry. – Ferdau Mar 05 '14 at 15:35
  • Off course, but when you get stuck on a single problem, not realizing what might be the problem you ask questions. All the other stuff I have managed by myself. And its not like I am jumping on here when I don´t get it. I have actually tried before I ask. So don´t be sorry, just helpful and the world will be a better place. It must be great being best at everything not sharing... Lucky for me some does and maybe my questions help others as well. – Jokez80 Mar 05 '14 at 16:03