0

在 Sony SmartWatch 2 上显示列表时出现问题。

我从示例项目(AdvancedControlSample)中复制了布局,并且我有以下类:

 public class OpenPositionsView extends ControlExtension implements BaseView {
    private static final String LOG_TAG = "TAGG";

    private Context context;
    private ControlViewGroup mLayout;

    public OpenPositionsView(Context context, String hostAppPackageName) {
        super(context, hostAppPackageName);
        this.context = context;
        mLayout = setup();
    }

    public ControlViewGroup setup() {
        Log.i(LOG_TAG, "setup");

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.watch_positions, null);
        ControlViewGroup mLayout = (ControlViewGroup) parseLayout(layout);

        return mLayout;
    }

    public void show(Controller parent) {

        int listCount = DataProvider.getInstance().getPositions().size();
        parent.sendListCountM(R.id.watch_positions_listview, listCount);
        parent.sendListPositionM(R.id.watch_positions_listview, 0);
        parent.refreshLayout(R.layout.watch_positions, null);


        Log.i(LOG_TAG, "show [listCount: " + listCount + "]");
    }

    @Override
    public void onRequestListItem(final int layoutReference, final int listItemPosition) {
        Log.d(LOG_TAG, "onRequestListItem [layoutReference: " + layoutReference + ", position: " + listItemPosition + "]");
        if (layoutReference != -1 && listItemPosition != -1 && layoutReference == R.id.watch_positions_listview) {
            ControlListItem item = createControlListItem(listItemPosition);
            if (item != null) {
                Log.d(LOG_TAG, "Sending list item");
                sendListItem(item);
            }
        }
    }

    @Override
    public void onListItemSelected(ControlListItem listItem) {
        super.onListItemSelected(listItem);
    }

    @Override
    public void onListItemClick(final ControlListItem listItem, final int clickType, final int itemLayoutReference) {
        Log.d(LOG_TAG, "onListItemClick [listItemPosition: " + listItem.listItemPosition + ", clickType: " + clickType + ", itemLayoutReference: "
                + itemLayoutReference + "]");
    }

    public void onClick(int id) {
        mLayout.onClick(id);
    }

    protected ControlListItem createControlListItem(int position) {
        Log.d(LOG_TAG, "createControlListItem [position: " + position + "]");

        ControlListItem item = new ControlListItem();
        item.layoutReference = R.id.watch_positions_listview;
        item.dataXmlLayout = R.layout.watch_positions_item;
        item.listItemPosition = position;

        // We use position as listItemId. Here we could use some other unique id
        // to reference the list data
        item.listItemId = position;

        Position target = DataProvider.getInstance().getPosition(position);

        if (target != null) {
            Bundle symbolBundle = new Bundle();
            symbolBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_symbol);
            symbolBundle.putString(Control.Intents.EXTRA_TEXT, target.getSymbol());

            Bundle typeBundle = new Bundle();
            typeBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_type);
            typeBundle.putString(Control.Intents.EXTRA_TEXT, target.getTypeAsString());

            item.layoutData = new Bundle[2];
            item.layoutData[0] = symbolBundle;
            item.layoutData[1] = typeBundle;
            Log.d(LOG_TAG, "Item list created: [symbolBundle: " + symbolBundle + ", typeBundle: " + typeBundle + "]");
        }

        return item;
    }

    protected Bundle[] createBundle(int position) {
        Bundle[] result = new Bundle[2];

        Position target = DataProvider.getInstance().getPosition(position);

        if (target != null) {
            Bundle symbolBundle = new Bundle();
            symbolBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_symbol);
            symbolBundle.putString(Control.Intents.EXTRA_TEXT, target.getSymbol());

            Bundle typeBundle = new Bundle();
            typeBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_type);
            typeBundle.putString(Control.Intents.EXTRA_TEXT, target.getTypeAsString());

            result[0] = symbolBundle;
            result[1] = typeBundle;
        }
        return result;
    }
}

但是,onRequestListItem被调用并createControlListItem返回正确的项目列表。触摸显示屏会给我以下结果:

onListItemClick [listItem: com.sonyericsson.extras.liveware.extension.util.control.ControlListItem@423b6960, clickType: 0, itemLayoutReference: -1]

问题是,我没有看到任何“添加”列表项:(

4

3 回答 3

1

确保您还从 Manifest.xml 复制了与列表相关的意图:

<action android:name="com.sonyericsson.extras.aef.control.LIST_REFERESH_REQUEST" />
<action android:name="com.sonyericsson.extras.aef.control.LIST_REQUEST_ITEM" />
<action android:name="com.sonyericsson.extras.aef.control.LIST_ITEM_CLICK" />
<action android:name="com.sonyericsson.extras.aef.control.LIST_ITEM_SELECTED" />
于 2013-11-15T22:38:49.030 回答
0

你不是在黑色背景的布局中添加黑色文本项吗?:) 请检查您的布局。

于 2013-11-26T14:27:52.273 回答
0

几个问题给你:

  1. 屏幕上显示的是什么?它只是空白吗?
  2. 你在调用 showLayout() 和 sendListCount() 吗?我在上面的代码中没有看到它们。在 onResume() 的示例代码中,您应该看到如下内容:

    showLayout(R.layout.layout_test_list, null); sendListCount(R.id.listView, mListContent.length);

    这些都需要调用。

  3. 你确定 sendListItem(item) 真的被调用了吗?

于 2013-11-18T22:16:02.583 回答