ListView - change items from 1 to 2 lines



How can I modify the code below so that each item has two lines instead of one? I want the code in the mSample section the same layout as I've posted so please do not inappropriately modify it unless it is necessary. Below is an image depicting what the list looks like with one line.


I know that the click event and list adapter codes needs to change, but I don't know what to.


I also have an xml called list_item_entry.xml that contains two text views (1 bigger than the other) in a linear layout but I'm not sure if I need to use that.


list view



public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Instantiate the list of samples.
mSamples = new Sample[]{
new Sample(R.string.title_crossfade, "Crossfade description", CrossfadeActivity.class),
new Sample(R.string.title_card_flip, "Card Flip description", CardFlipActivity.class),
new Sample(R.string.title_screen_slide, "Screen Slide description", ScreenSlideActivity.class),
new Sample(R.string.title_zoom, "Zoom description", ZoomActivity.class),
new Sample(R.string.title_layout_changes, "Layout Changes description", LayoutChangesActivity.class),
};

setListAdapter(new ArrayAdapter<Sample>(this,
android.R.layout.simple_list_item_1,
android.R.id.text1,
mSamples));
}

@Override
protected void onListItemClick(ListView listView, View view, int position, long id) {
// Launch the sample associated with this list position.
startActivity(new Intent(MainActivity.this, mSamples[position].activityClass));
}


list_item_entry.xml



<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize"
android:baselineAligned="false">

<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">

<TextView android:id="@+id/list_item_entry_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
/>

<TextView android:id="@+id/list_item_entry_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/list_item_entry_title"
android:layout_alignLeft="@id/list_item_entry_title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="true"
android:textColor="?android:attr/textColorSecondary"
/>

</RelativeLayout>

</LinearLayout>

No comments:

Post a Comment