Question

Three Questions Here Mainly:

1. I am trying to display a listview with my own layout inside an activity. For this first I create a set of static cards and then by using an onItemClickListener I create an intent and start activity. But that doesnt seem to work. There are two activities here. One is the CradsScrollActivity(Working) with static cards and next is ListCardsScrollActivity with my customlayout. The CardsScrollActivity calls the ListCardsScrollActivity (with the listview), but this is not working, but the logcat says it started the activity and displaying it. Here is my CardsScrollActivity

public class CardsScrollActivity extends Activity {

    private List<Card> mCards;
    private CardScrollView mCardScrollView;
    private List<CardData> mCardsData;

    private static final String TAG = "CardScrollActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        createSomeCards();

        mCardScrollView = new CardScrollView(this);
        TestCardScrollAdapter adapter = new TestCardScrollAdapter(mCards, mCardsData, this);
        mCardScrollView.setAdapter(adapter);
        mCardScrollView.activate();




        mCardScrollView.setOnItemClickListener(new OnItemClickListener()
        {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int pos,
                    long id) {
                Log.d(TAG, "item tapped: "+pos); //working ! 
                Intent i = new Intent(CardsScrollActivity.this, ListCardsScrollActivity.class);

                startActivity(i);
            }

        });

        setContentView(mCardScrollView);
    }




      private void createSomeCards()
      {
            mCardsData = new ArrayList<CardData>();
        mCards = new ArrayList<Card>();
        Card card;  
        card = new Card(this);
        mCardsData.add(new CardData("Welcome","Swipe To Enter"));
        mCards.add(card);  
        card = new Card(this);
            card.setImageLayout(Card.ImageLayout.FULL);
            card.addImage(R.drawable.img1);
            mCardsData.add(new CardData("Background Image","Step 1"));
            mCards.add(card);
            card = new Card(this);
            card.setImageLayout(Card.ImageLayout.LEFT);
            card.addImage(R.drawable.img1);
            card.addImage(R.drawable.img2);
            mCardsData.add(new CardData("Step 1 and Step 2","End Of Cards"));
            mCards.add(card);
      }}

As you see the onClickListener is working fine, it receives that call, but the intent part is not working. Here is my ListCardsScrollActivity

public class ListCardsScrollActivity extends Activity {



    private static final String TAG = "ListCardsScrollActivity";

    private  List<String> mList ;

    private ListView mListView;

    private TestListAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_view);
        populateArrayList();
        mListView = (ListView)findViewById(R.id.listView);
        mAdapter = new TestListAdapter(this,R.layout.list_element,mList);
        mListView.setAdapter(mAdapter);
    }

    private void populateArrayList()
    {
        mList = new ArrayList<String>();
        mList.add("Item 1");
        mList.add("Item 2");
        mList.add("Item 3");
        mList.add("Item 4");
        mList.add("Item 5");
        mListView = (ListView)findViewById(R.id.listView);
        mAdapter = new TestListAdapter(this,R.layout.list_element,mList);
        mListView.setAdapter(mAdapter);
    }

Is there anyway I can create my own static cards with custom layouts?

Are live cards supposed to be published onto the timeline manager always or can it be within our glassware app? It would be great if anyone could share an example where a listview is implemented in live cards.

Thanks in advance.

Was it helpful?

Solution

Ok despite for the fear of being down voted for this really dirty way, I would like to share this one as answer, so that anyone could improve on it or come up with a lot more better implementation:

  1. As I am just playing around with the glass, I did the belwo thing, now I am doing this whole stuff programtically so thats Its dynamic . For the record, my so called list layout would be:

    <Button 
        android:id="@+id/btn1"
        android:text="Btn 1"
        android:background="#CD3333"
        android:focusable="true"
        android:textSize="14sp"
        android:textStyle="bold"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000000"/>
     <Button 
        android:id="@+id/btn2"
        android:text="Btn 2"
        android:textStyle="bold"
        android:textSize="14sp"
        android:background="#CD3333"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"/>
      <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000000"/>
      <Button 
        android:id="@+id/btn3"
        android:text="Btn 3"
        android:textStyle="bold"
        android:textSize="14sp"
        android:background="#CD3333"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"/>
       <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000000"/>
       <Button 
        android:id="@+id/btn4"
        android:text="Btn 4"
        android:background="#CD3333"
        android:textStyle="bold"
        android:textSize="14sp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"/>
        <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000000"/>
        <Button 
        android:id="@+id/btn5"
        android:text="Btn 5"
        android:textSize="14sp"
        android:textStyle="bold"
        android:background="#CD3333"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"/>
    

and in my Activity I would do this:

 public class ButtonListActivity extends Activity implements View.OnFocusChangeListener {

        public static final String TAG = "ButtonListActivity";

        Button mButton1;
        Button mButton2;
        Button mButton3;
        Button mButton4;
        Button mButton5;

        Bundle extras;

        ArrayList<String> list;


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.list_template);

            list = new ArrayList<String>();


            mButton1 = (Button)findViewById(R.id.btn1);
            mButton2 = (Button)findViewById(R.id.btn2);
            mButton3 = (Button)findViewById(R.id.btn3);
            mButton4 = (Button)findViewById(R.id.btn4);
            mButton5 = (Button)findViewById(R.id.btn5);


            extras = getIntent().getExtras();

            if(extras!=null)
            {
              list = extras.getStringArrayList("list"); 

            }

            mButton1.setText(list.get(0));
            mButton2.setText(list.get(1));
            mButton3.setText(list.get(2));
            mButton4.setText(list.get(3));
            mButton5.setText(list.get(4));


            mButton5.setFocusableInTouchMode(true);
            mButton5.setOnFocusChangeListener(this);

            mButton4.setFocusableInTouchMode(true);
            mButton4.setOnFocusChangeListener(this);

            mButton3.setFocusableInTouchMode(true);
            mButton3.setOnFocusChangeListener(this);

            mButton2.setFocusableInTouchMode(true);
            mButton2.setOnFocusChangeListener(this);

            mButton1.setFocusableInTouchMode(true);
            mButton1.setOnFocusChangeListener(this);
        }


        @Override
        public void onFocusChange(View v, boolean hasFocus) {

           if(v.hasFocus()) 
            v.setBackgroundColor(Color.parseColor("#0EBFE9"));
           else
               v.setBackgroundColor(Color.parseColor("#CD3333"));
        }
    }

So the actual output would appear as a list with orange background and the listener would help you make your selection as you go up and down your list. The list elements are set with the intent extras I am getting. In this case a string array list. So the final produce is a listview looking like layout.

  1. I resolved this by using the standard android layouts, more or less like an "immersion". Baseline: Not using cards

  2. This is more of a comment than an answer, please correct me if wrong, live cards are supposed to be pushed to timeline manager and for the other half question, I did not see an example of a low frequency live cards using a the views mentioned here:

https://developers.google.com/glass/develop/gdk/ui/live-cards

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top