0

Watch の 2 つの TextView のテキストを同時に更新したいと思います。

main_layout.xml

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <TextView
        android:id="@+id/text1"
        android:layout_width="220px"
        android:layout_height="50px"
        />
    <TextView
        android:id="@+id/text2"
        android:layout_width="220px"
        android:layout_height="50px"
        />
</LinearLayout>

今、私はこのようにしています:

sendText(R.id.text1, "Hello world 1");
sendText(R.id.text2, "Hello world 2");

問題は、ウォッチでわかるように、最初のテキストが先に設定され、次に 2 番目のテキストが設定されていることです。そして、私はそれを避けたいと思います。

一般に、Sony-SDK は、たとえばレイアウトを表示する場合など、バンドル内のデータ更新をサポートします。

Bundle b1 = new Bundle();
b1.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.text1);
b1.putString(Control.Intents.EXTRA_TEXT, "Hello world 1");

Bundle b2 = new Bundle();
b2.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.text2);
b2.putString(Control.Intents.EXTRA_DATA_URI, "Hello world 2");

Bundle[] layoutData = new Bundle[] { b1, b2 };

showLayout(R.layout.main_layout, layoutData);

ただし、この場合、レイアウトが再設定されます。これは、画面上の他のビューが既に変更されている可能性があるため、私の場合はあまり良くありません。

私は、次のような方法でこれを達成できることを願っていました:

Bundle bundle = new Bundle();
bundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.text2);
bundle.putString(Control.Intents.EXTRA_TEXT, "Hello world 2");

Intent intent = new Intent(Control.Intents.CONTROL_SEND_TEXT_INTENT);

intent.putExtra(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.text1);
intent.putExtra(Control.Intents.EXTRA_TEXT, "Hello world 1");

intent.putExtra(Control.Intents.EXTRA_LAYOUT_DATA, new Bundle[] { bundle });

sendToHostApp(intent);

残念ながら、ウォッチは CONTROL_SEND_TEXT_INTENT インテントの EXTRA_LAYOUT_DATA を無視しているようです。

私の質問は、レイアウトを再設定せずにテキストの更新をバンドルとして送信する可能性はありますか?

4

1 に答える 1

0

あなたはそれを正しくやっています。画面全体を更新するのが最善の方法です。その間に変更された可能性のある他のすべてのフィールドも更新するだけです。

于 2013-10-17T12:06:38.480 に答える