因此,在我的应用程序中,我使用ListView来显示来自保存对象的ArrayList的数据。格式化ListView的特定部分项目
// automatically adds a ListView to fill the entire screen of this activity
setListAdapter(new ArrayAdapter<Part>(this, R.layout.list_item, Main.parts));
ListView lv = getListView();
// allows the user to start typing to filter the list
lv.setTextFilterEnabled(true);
// set the click listener for each list item
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}
});
目前的对象都显示在每个LIST_ITEM:
<!-- Defines the layout for each item being placed in the ListView. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
所以我返回每个对象作为这样的:数据使用同样的方法,在Android开发者网站上的教程显示
public String toString() {
return "Item Number: " + itemNmbr + "\nPrice: " + price + "\nDescription: " + desc;
}
的名单目前的样子的一个例子:
http://imageshack.us/photo/my-images/689/devicet.png/
问题是,我需要格式化标题与数据分开。 (因为它需要大胆,并可能间隔一点点。)
任何想法?我目前正在测试如何让两个文本浏览器一起工作。
谢谢!
这里是我落得这样做: http://devtut.wordpress.com/2011/06/09/custom-arrayadapter-for-a-listview-android/ – Cody 2011-06-09 05:02:13