2011-06-08 25 views
0

因此,在我的應用程序中,我使用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/

問題是,我需要格式化標題與數據分開。 (因爲它需要大膽,並可能間隔一點點。)

任何想法?我目前正在測試如何讓兩個文本瀏覽器一起工作。

謝謝!

+0

這裏是我落得這樣做: http://devtut.wordpress.com/2011/06/09/custom-arrayadapter-for-a-listview-android/ – Cody 2011-06-09 05:02:13

回答

0
+0

感謝。這使我朝着正確的方向發展,我會稍微張貼一些示例代碼,以防其他人需要某些類似的指導 - 我發現開發人員所做的一些事情有些不必要。 – Cody 2011-06-08 20:54:01