1

必要な情報を表示するために約 700 のアクティビティが必要な大量の情報を含むアプリを開発しているので、700 のアクティビティを作成する代わりに、情報を XML ファイルに入れて解析します。XML ファイルから解析された情報に基づいて情報を表示する 1 つのアクティビティが必要です。

<item>
   <name>Monkey</name>
   <type>flying</type>
</item>
<item>
   <name>Kangaroo</name>
   <type>Brown</type>
</item>

そのため、Monkey を解析すると、Activity はそのアイテムのすべての情報を表示します。この場合、それが飛んでいるタイプの Monkey であることを示します。

例:

解析された猿:

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="18dp"
    android:layout_marginTop="17dp"
    android:text="Monkey"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="22dp"
    android:text="flying"
    android:textAppearance="?android:attr/textAppearanceMedium" />

解析されたカンガルー:

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="18dp"
    android:layout_marginTop="17dp"
    android:text="Kangaroo"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="22dp"
    android:text="Brown"
    android:textAppearance="?android:attr/textAppearanceMedium" />
4

1 に答える 1

0

私はあなたの質問を理解できないようですが、そうです - あなたは間違いなくAndroidでこれを行うことができます. あなたの例では、変数(名前とタイプ)を含むオブジェクトがあります。xml を解析し、xml 値をオブジェクト メンバーにマッピングします。それなら、あとはTextView.setText(). XML の代わりに JSON の使用を検討することをお勧めします。

于 2013-10-10T03:23:09.553 に答える