Listview in Sony Smartwatch 2

210 views Asked by At

I'm trying to show a list in Sony Smartwatch 2 in the Control Class. I am doing the same as for a TextView:

// Prepare a bundle to update text. Bundle bundle1 = new Bundle();

    bundle1.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.text);
    bundle1.putString(Control.Intents.EXTRA_TEXT, "Helloooooo");

And this works fine, but I don't know how to do it for ListView, something like this doesn't work:

    String[] values = new String[] { "Android", "iPhone",
          "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7",
          "Max OS X", "Linux", "OS/2", "Ubuntu", "Windows7", "Max OS X",
          "Linux", "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2",
          "Android", "iPhone", "WindowsMobile" };

    final ArrayList<String> list = new ArrayList<String>(); 
    for (int i = 0; i < values.length; ++i) { 
        list.add(values[i]); 
        } 
    final StableArrayAdapter adapter = new StableArrayAdapter(this,android.R.layout.simple_list_item_1, list);

    // Prepare a bundle to update the button text.
    Bundle bundle1 = new Bundle();

    bundle1.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.list);
    bundle1.putStringArray(Control.Intents.EXTRA_DATA, values);

Please help me :S, I think it is something like this:

        Bundle b = new Bundle();
        b.putInt(Control.Intents.EXTRA_DATA_XML_LAYOUT,
            R.layout.smartwatch2_item);
        b.putInt(Control.Intents.EXTRA_LIST_ITEM_ID, i);
        b.putInt(Control.Intents.EXTRA_LIST_ITEM_POSITION, i);
        b.putParcelableArray(Control.Intents.EXTRA_LAYOUT_DATA, views);
2

There are 2 answers

0
leak4mk0 On BEST ANSWER

Items of SmartWatch's ListView can be sent only by sendListItem(ControlListItem item). Usually, sendListItem is called in onRequestListItem Callback. onRequestListItem is called when sendListCount and sendListPosition is called.

So, you should not send item by adapter, should call sendListCount and sendListPostion.

ControlListItem has dataXmlLayout and layoutData. dataXmlLayout should be item's layout. layoutData should be bundle array.

public void onResume(int layoutReference, int listItemPosition) {
    showLayout(YOUR_LAYOUT_HAS_LIST_VIEW);
    sendListCount(values.length);
    sendListPosition(YOUR_LIST_VIEW, 0);
}
public void onRequestListItem(int layoutReference, int listItemPosition) {
    ControlListItem item = new ControlListItem();
    item.layoutReference = layoutReference;
    item.dataXmlLayout = android.R.layout.simple_list_item_1;
    item.listItemId = listItemPosition;
    item.listItemPosition = listItemPosition;
    item.layoutData = new Bundle[1];
    item.layoutData[0] = new Bundle();
    item.layoutData[0].putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, android.R.id.text1);
    item.layoutData[0].putString(Control.Intents.EXTRA_TEXT, values[listItemPosition]);
    sendListItem(item);
}

Please attention to that SmartWatch's layout support is limited.

2
Vikram Ezhil On

You have created the adapter, but haven't added the adapter to the list view.

I am not able to pin-point your exact issue, since your main activity code is incomplete.

To access your list view from your layout, add the below code

ListView lv = (ListView) this.findViewById(R.id.yourlistviewIDname));

ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, your_list);

lv.setAdapter(adapter);