简体   繁体   中英

Formatting Specific Parts of a Listview Item

So in my application I am using a ListView to display data from an ArrayList which holds objects. The data is displayed using the same method as the tutorial on the android developer website:

        // 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();
        }
    });

The objects are currently displayed in each 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>

So I return each object as such:

    public String toString() {
    return "Item Number: " + itemNmbr + "\nPrice: " + price + "\nDescription: " + desc;
}

An example of how the list currently looks:

http://imageshack.us/photo/my-images/689/devicet.png/

The problem is, I need to format the title separately from the data. (because it needs to be bold, and possibly spaced out a little further.)

Any ideas? I'm currently testing on how to get two textviews to work together.

Thank you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM