自定义列表视图不显示

时间:2012-07-11 20:28:52

标签: android android-listview android-adapter

我在做什么:

  

我正在编写一个与地图和路线等有关的Android应用程序。在应用程序的主屏幕上,有一个按钮可以打开收藏夹页面。收藏夹页面由以下xml布局组成。

layout_favorites.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mainscreen2">
        <HorizontalScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarSize="0dp"
        >
            <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
                <ImageView
                android:id="@+id/imageViewfavorites"
                android:scaleType="fitEnd"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="3dp"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:layout_width="60px"
                android:layout_height="60px"
                android:src="@drawable/android_button_44_2"/>
                <TextView
                android:id="@+id/textview_favorites"
                android:background="@null"
                android:scaleType="fitEnd"
                android:layout_marginTop="15dp"
                android:layout_marginBottom="3dp"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:layout_width="wrap_content"
                android:layout_height="60px"
                android:textSize="35sp"
                android:textColor="#000000"
                android:text="Favorites"/>
            </LinearLayout>
        </HorizontalScrollView>
        <ListView
            android:id="@+id/listview_favorites"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="45dp"
            android:cacheColorHint="#00000000"
            >
            </ListView>
</LinearLayout>

这很好用,不用担心。在顶部布局中,您将看到有一个ListView。我想用这样的行填充ListView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dip" >
        <ImageView
            android:id="@+id/route_image"
            android:layout_width="50dip"
            android:layout_height="50dip"/>
    <TextView
        android:id="@+id/route_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/route_image"
        android:layout_toRightOf="@+id/route_image"
        android:textColor="#000000"
        android:textSize="15dip"
        android:textStyle="bold"/>
    <TextView
        android:id="@+id/route_author"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/route_title"
        android:textColor="#000000"
        android:textSize="10dip"
        android:layout_marginTop="1dip"
        android:layout_toRightOf="@+id/thumbnail"/>
    <TextView
        android:id="@+id/route_length"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@id/route_title"
        android:gravity="right"
        android:layout_marginRight="5dip"
        android:textSize="10dip"
        android:textColor="#10bcc9"
        android:textStyle="bold"/>
     <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/arrow"/>
</RelativeLayout>

所以最后看起来应该是这样的:

(绘制的图像:p) http://s9.postimage.org/cgcahc1i7/Untitled.png

OR

http://imageshack.us/photo/my-images/694/67362201.png/

现在,这是问题所在的地方。它没有显示出来。我正在使用扩展BaseAdapter类的自定义适配器来处理Listview并使视图等膨胀。我将发布Adapater,然后发布收藏夹活动屏幕。

适配器类:

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


/**
 *
 * @author Gideon
 */
public class Adapter_Maplist_Page_Favorites extends BaseAdapter
{
    //----------------------------------------
    //  Variables
    //----------------------------------------
        private Context context;
        private final Drawable[] drawables;
        private final String[] titles;
        private final String[] authors;
        private final String[] durations;
    //----------------------------------------

    //----------------------------------------
    //  Methods
    //----------------------------------------


        public Adapter_Maplist_Page_Favorites(Context context ,String[] titles,String[] authors,String[] durations,Drawable[] drawables)
        {

            this.context = context;
            this.titles = titles;
            this.authors = authors;
            this.durations = durations;
            this.drawables = drawables;
        }

        public View getView(int position, View convertView, ViewGroup parent)
        {

                LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View rowView = inflater.inflate(R.layout.layout_favorites_row, parent);


                ImageView map_image = (ImageView) rowView.findViewById(R.id.route_image);
            TextView map_title = (TextView) rowView.findViewById(R.id.route_title);
            TextView map_author = (TextView) rowView.findViewById(R.id.route_author);
                TextView map_length = (TextView) rowView.findViewById(R.id.route_length);
                ImageView map_image_arrow = (ImageView) rowView.findViewById(R.drawable.arrow);

                map_image.setBackgroundDrawable(drawables[position]);
                map_title.setText(titles[position]);
                map_author.setText(authors[position]);
                map_length.setText(durations[position]);
                map_image_arrow.setBackgroundDrawable(map_image_arrow.getBackground());


        return rowView;
    }
        //----------------------------------------

        //----------------------------------------
        // Not Implemented
        //----------------------------------------
        public Object getItem(int arg0)
        {
            return null;
        }

        public long getItemId(int position)
        {
           return 0;
        }

        public int getCount()
        {
            throw new UnsupportedOperationException("Not supported yet.");
        }
            //----------------------------------------
    //----------------------------------------
}

收藏夹活动类:

import android.app.ListActivity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;



/**
 *
 * @author Gideon
 */
public class Page_Favorites extends ListActivity
{
    //---------------------------------------------------------------------------------------------------------------
    //Hierdie info sal in die toekoms vanaf die databsae moet kom of net vervang word met die database entries in for loops etc. (This info will be loaded from the database in the future)
    //---------------------------------------------------------------------------------------------------------------
    public final String[] map_titles = {"Route 1","Route 2","Route 3","Route 4","Route 5","Route 6"};
    public final String[] map_authors = {"Jannie","Sannie","Bennie","Kosie","Gideon","Alex"};
    public final String[] map_lengths = {"42km","2km","21.5km","8km","34km","23km"};
    ImageView iv = (ImageView) findViewById(R.drawable.route_image_1);
    public final Drawable[] map_images = {iv.getBackground(),iv.getBackground(),iv.getBackground(),iv.getBackground(),iv.getBackground(),iv.getBackground()};
    //---------------------------------------------------------------------------------------------------------------

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        overridePendingTransition(R.layout.animation_fadein, R.layout.animation_fadeout);
        setContentView(R.layout.layout_favorites);
        // ToDo add your GUI initialization code here

        ListView list = (ListView) findViewById(R.id.listview_favorites);
        list.setAdapter(new Adapter_Maplist_Page_Favorites(this, map_titles, map_authors, map_lengths, map_images));

        list.setOnItemClickListener(new OnItemClickListener()
        {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id)
            {
               Toast.makeText(Page_Favorites.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }
}

当我点击按钮启动收藏夹屏幕/活动并创建列表视图时,应用程序退出并显示错误(被迫退出...)。任何帮助或想法将不胜感激。 THX。

修改

Adb记录错误:

22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime  FATAL EXCEPTION: main
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime  java.lang.RuntimeException: Unable to start activity ComponentInfo{RedPheasant.LoggerApp/RedPheasant.LoggerApp.Page_Favorites}: java.lang.NullPointerException
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.app.ActivityThread.access$1500(ActivityThread.java:117)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.os.Handler.dispatchMessage(Handler.java:99)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.os.Looper.loop(Looper.java:123)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.app.ActivityThread.main(ActivityThread.java:3687)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at java.lang.reflect.Method.invokeNative(Native Method)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at java.lang.reflect.Method.invoke(Method.java:507)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at dalvik.system.NativeStart.main(Native Method)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime  Caused by: java.lang.NullPointerException
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at RedPheasant.LoggerApp.Page_Favorites.onCreate(Page_Favorites.java:48)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
22:54:21.505    24082   ERROR   RedPheasant.LoggerApp   AndroidRuntime      ... 11 more
22:54:21.515    212 ERROR   #212        Dumpstate > /data/log/dumpstate_app_error

另外,修复了这部分:

public int getCount()
    {
       if(titles == null)
        {
            return 0;
        }
        return titles.length;
    }

仍然遇到同样的问题。 编辑2:

好的,伙计们,到目前为止所有的帮助......

我进一步改变了这个:

新收藏页面活动(已修改):

public class Page_Favorites extends Activity
{




    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        overridePendingTransition(R.layout.animation_fadein, R.layout.animation_fadeout);
        setContentView(R.layout.layout_favorites);
        // ToDo add your GUI initialization code here

        //---------------------------------------------------------------------------------------------------------------
        //Hierdie info sal in die toekoms vanaf die databsae moet kom of net vervang word met die database entries in for loops etc.
        //---------------------------------------------------------------------------------------------------------------


        String[] map_titles = {"Route 1","Route 2","Route 3","Route 4","Route 5","Route 6"};
        String[] map_authors = {"Jannie","Sannie","Bennie","Kosie","Gideon","Alex"};
        String[] map_lengths = {"42km","2km","21.5km","8km","34km","23km"};
        //ImageView iv = (ImageView) findViewById(R.drawable.route_image_1);
        Drawable d = getResources().getDrawable(R.drawable.route_image_1);
        Drawable[] map_images = {d,d,d,d,d,d};
        Drawable d2 = getResources().getDrawable(R.drawable.arrow);
       //---------------------------------------------------------------------------------------------------------------

        ListView list = (ListView) findViewById(R.id.listview_favorites);
        list.setAdapter(new Adapter_Maplist_Page_Favorites(this, map_titles, map_authors, map_lengths, map_images,d2));//lika a boss itches

        list.setOnItemClickListener(new OnItemClickListener()
        {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id)
            {
               Toast.makeText(Page_Favorites.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }
}

新的Adapter类(已修改):

public class Adapter_Maplist_Page_Favorites extends BaseAdapter
{
    //----------------------------------------
    //  Variables
    //----------------------------------------
        private Context context;
        private final Drawable[] drawables;
        private final String[] titles;
        private final String[] authors;
        private final String[] durations;
        private final Drawable d;
    //----------------------------------------

    //----------------------------------------
    //  Methods
    //----------------------------------------


        public Adapter_Maplist_Page_Favorites(Context context ,String[] titles,String[] authors,String[] durations,Drawable[] drawables,Drawable d)
        {

            this.context = context;
            this.titles = titles;
            this.authors = authors;
            this.durations = durations;
            this.drawables = drawables;
            this.d = d;
        }
        //----------------------------------------


        public View getView(int position, View convertView, ViewGroup parent)
        {

                LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.layout_favorites_row, parent);


                ImageView map_image = (ImageView) rowView.findViewById(R.id.route_image);
        TextView map_title = (TextView) rowView.findViewById(R.id.route_title);
        TextView map_author = (TextView) rowView.findViewById(R.id.route_author);
                TextView map_length = (TextView) rowView.findViewById(R.id.route_length);

                ImageView map_image_arrow = (ImageView) rowView.findViewById(R.id.route_arrow);

                map_image.setBackgroundDrawable(drawables[position]);
                map_title.setText(titles[position]);
                map_author.setText(authors[position]);
                map_length.setText(durations[position]);
                map_image_arrow.setBackgroundDrawable(d);


        return rowView;
    }
        //----------------------------------------

        //----------------------------------------
        // Not Implemented
        //----------------------------------------
        public Object getItem(int arg0)
        {
            return null;
        }

        public long getItemId(int position)
        {
           return 0;
        }

        public int getCount()
        {
           if(titles == null)
            {
                return 0;
            }
            return titles.length;
        }
            //----------------------------------------
    //----------------------------------------
}

新错误日志adblog:

23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime  FATAL EXCEPTION: main
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime  java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.widget.AdapterView.addView(AdapterView.java:461)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.view.LayoutInflater.inflate(LayoutInflater.java:416)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at RedPheasant.LoggerApp.Adapter_Maplist_Page_Favorites.getView(Adapter_Maplist_Page_Favorites.java:73)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.widget.AbsListView.obtainView(AbsListView.java:1554)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.widget.ListView.makeAndAddView(ListView.java:1793)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.widget.ListView.fillDown(ListView.java:718)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.widget.ListView.fillFromTop(ListView.java:775)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.widget.ListView.layoutChildren(ListView.java:1646)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.widget.AbsListView.onLayout(AbsListView.java:1384)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.view.View.layout(View.java:7228)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.view.ViewRoot.performTraversals(ViewRoot.java:1147)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.os.Handler.dispatchMessage(Handler.java:99)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.os.Looper.loop(Looper.java:123)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at android.app.ActivityThread.main(ActivityThread.java:3687)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at java.lang.reflect.Method.invokeNative(Native Method)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at java.lang.reflect.Method.invoke(Method.java:507)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
23:15:15.839    24746   ERROR   RedPheasant.LoggerApp   AndroidRuntime      at dalvik.system.NativeStart.main(Native Method)
23:15:15.849    212 ERROR   #212        Dumpstate > /data/log/dumpstate_app_error

到目前为止帮助Thx ...但仍然得到相同的错误。

更新

我猜这是我现在的主要问题:

java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

我猜这与不支持视图的适配器有关。我有点困惑:p lol。任何想法。

最终编辑 - 已解决 感谢所有帮助人员。它终于工作了,看起来很棒。

我将绘图分配给ImageViews的方式存在的主要问题,这些问题在进行膨胀时会导致问题。 Thx Sam指出了这一点。另一个主要问题是我必须将false参数添加到inflate方法,而不是将其复制到root。 Thx Angelo指出了这一点。

4 个答案:

答案 0 :(得分:3)

如果没有LogCat,我们只能猜测你有什么错误......

1)您正在扩展ListActivity:

public class Page_Favorites extends ListActivity

要求您在传递给setContentView()的布局中有一个属性为android:id="@android:id/list"的ListView。我只是建议你只扩展一个活动:

public class Page_Favorites extends Activity

因为您当前的代码不依赖于ListActivity。

2)脱离背景:

ImageView iv = (ImageView) findViewById(R.drawable.route_image_1);
public final Drawable[] map_images = {iv.getBackground(),iv.getBackground(),iv.getBackground(),iv.getBackground(),iv.getBackground(),iv.getBackground()};

在创建Activity之前,不能引用findViewById(),这应该在setContentView()之后的onCreate()中完成。

3)您应该将drawable加载到ImageView中,如下所示:

ImageView iv = (ImageView) findViewById(R.id.imageViewfavorites);
iv.setImageResource(R.drawables.route_image_1);

我猜到了你想要的图像...这是你的意思吗?

已经有足够的人对getCount()进行了评论,所以我不会重申它。

4)在你的适配器的getView()中,改变它:

View rowView = inflater.inflate(R.layout.layout_favorites_row, parent);

到此:

View rowView = inflater.inflate(R.layout.layout_favorites_row, parent, false);

答案 1 :(得分:1)

为什么你有 getCount()方法,它应该返回一个抛出异常的int值?这看起来很尴尬。而不是你应该这样做:

public int getCount()
{
    return yourDataArray.size();
}

该方法负责ListView将具有的行数,即,如果 yourDataArray 的大小= 7,则表示在ListView中将有7行。

修改

以下是您的解决方案:

  1. 将getItem()方法替换为:

     public Object getItem(int arg0)
     {
         return arg0;
     }
    
  2. 使用以下代码替换适配器getView()方法。

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        ViewHolder holder;
    
        if (v == null) {
             LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             View rowView = vi.inflate(R.layout.layout_favorites_row, null);
    
             ImageView map_image = (ImageView) rowView.findViewById(R.id.route_image);
             TextView map_title = (TextView) rowView.findViewById(R.id.route_title);
             TextView map_author = (TextView) rowView.findViewById(R.id.route_author);
             TextView map_length = (TextView) rowView.findViewById(R.id.route_length);
             ImageView map_image_arrow = (ImageView) rowView.findViewById(R.id.route_arrow);
    
            v.setTag(holder);
        }
        else {
            holder=(ViewHolder)v.getTag();
        }
    
        /** Define here the values to all the Views of the ViewHolder. */
        holder.map_image.setBackgroundDrawable(drawables[position]);
        holder.map_title.setText(titles[position]);
        holder.map_author.setText(authors[position]);
        holder.map_length.setText(durations[position]);
        holder.map_image_arrow.setBackgroundDrawable(d);
    
    return v;
    }
    

    使用ViewHolder。确保定义一个ViewHolder内部类,如:

    public static class ViewHolder {
          public TextView map_image ;
          public TextView map_title;
          public TextView map_author;
          public TextView map_length;
          public ImageView map_image_arrow;
    }
    

答案 2 :(得分:0)

检查此方法:

public int getCount()
        {
            throw new UnsupportedOperationException("Not supported yet.");
        }

返回值&gt;它最近给了我很多帮助。我不确定你的问题,但试试吧。

答案 3 :(得分:0)

这是你的问题:

public int getCount()
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

您应该返回列表中的元素数量。像这样:

public int getCount()
    {
        if(title == null) {
           return 0;
        }
        return title.length;
    }

此外,Sam说的是你应该解决的另一个问题。

编辑查看您的适配器代码我发现您没有使用ViewHolder。我强烈建议您使用它,因为它可以显着地利用listView的性能。 Here是一个很好的链接,它解释了有关listView的所有基础知识。以上评论只是为了表现,但包含它是好的。

来自this SO question得分最高的答案。改变这一行:

View rowView = inflater.inflate(R.layout.layout_favorites_row, parent);

用这个:

View rowView = inflater.inflate(R.layout.layout_favorites_row, parent, false);

我想你不会有任何问题。