0
我試圖在列表中顯示一些項目的名稱,然後單擊,我應該顯示更多,甚至可以更新/編輯內容。我的活動XML看起來是這樣的:在ListView中僅顯示xml中的特定屬性Android
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_list_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#035E7B"
tools:context="com.example.melisaam.logintest.ListItemsActivity">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:entries="@array/sections" >
</ListView>
</RelativeLayout>
而我的陣列XML是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="sections">
<item>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>
Two of our famous Belgian Waffles with plenty of real maple syrup
</description>
<calories>650</calories>
</item>
<item>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>
Light Belgian waffles covered with strawberries and whipped cream
</description>
<calories>900</calories>
</item>
<item>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>
Belgian waffles covered with assorted fresh berries and whipped cream
</description>
<calories>900</calories>
</item>
<item>
<name>French Toast</name>
<price>$4.50</price>
<description>
Thick slices made from our homemade sourdough bread
</description>
<calories>600</calories>
</item>
<item>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>
Two eggs, bacon or sausage, toast, and our ever-popular hash browns
</description>
<calories>950</calories>
</item>
</string-array>
</resources>
目前我加載我的項目這種方式在我的活動:
Log.d(TAG, "Trying to create the list activity");
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_list_items);
//* *EDIT* *
this.listView = (ListView) findViewById(R.id.listView1);
但這不是很好。我所有的屬性都放在我的列表中。我想在我的列表視圖中只顯示名稱和價格,點擊後應該會顯示其他信息。任何想法如何我可以做到這一點,而無需XML解析器或是唯一的解決方案?