开发者

TextView and ListView in a LinearLayout

I searched for similar questions but didn't get the proper answer, so posting it as a new question.

Can a LinearLayout have two TextViews and one list view? I learn that listview can be used to display array elements only if the class extends ListActivity. The Class in my app extends Activity and uses listView.

I am trying to build an RSS Reader based on IBM tutorial. On running the project I am getting parsed text in both the Text views but ListView is not displaying. I can开发者_如何学运维 post the code and Logcat if required.


Linear Layout can have any number of children. ListActivity is an Activity that Android have added for convenience when dealing with activities comprised of list.

You can use ListView on a regular Activity and just implement an adapter that will populate the list items with data from your model.

Android has some ready-made adapters that can be used for simple use-cases. of course if you need a more complicated beahviour you can extend them.

Have a look on BaseAdapter, ArrayAdapter and CursorAdapter to get a better understanding of how to use adapters.


You can have a ListView in any activity, using a ListActivity just makes your life easier (usually). See here for details.


You can have a Linear layout with different views and list view inside for example:

?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="fill_parent"
  android:orientation="vertical"
  android:background="@drawable/background_new_search_activity_1">

<TextView
            android:id="@+id/list_item_amount_text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:cacheColorHint="#00000000"/>

</LinearLayout>

And yes you can use the ListViewin all the activities, it is not necessary to extend ListActivity


Make sure the orientation of the ListView is set to vertical. Otherwise, it will try to display all items side by side, and those that fall outside the available view area won't be visible.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical">    <!-- << orientation setting here -->
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜