我试图在列表中显示某些项目的名称,然后点击,我应该显示更多,甚至可以更新/编辑内容。我的活动xml如下所示:
<?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);
但这不是很好。我的所有属性都放在我的列表中的一行中。我希望在我的listview中只显示名称和价格,点击后,应显示其他信息。如果没有xml解析器我是如何做到这一点的,或者这是唯一的解决方案?
答案 0 :(得分:0)
您需要定义自己的列表视图布局,并通过列表适配器进行映射。而且根据我的理解,您需要ExpandableListView
,以便在按下时显示更多项目。