Janpan
Janpan

Reputation: 2284

Custom Listview not displaying

What I am doing:

I am writing an android app that has to do with maps and routes etc. On the home screen of the application , there is a button that opens the favorites page. The favorites page is comprised out of the following xml layout.

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>

This is working fine , no worries. In the top layout , you will see there is a ListView. I want to populate that ListView with rows looking like this:

<?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>

So in the end , it should look something like this:

(image drawn in paint :p) http://s9.postimage.org/cgcahc1i7/Untitled.png

OR

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

Now, heres where the problem comes in. It does not display. I am using a custom Adapter that extends the BaseAdapter class to handle the Listview and inflate the view etc. I will post the Adapater and then the Activity for the Favorites screen.

Adapter class:

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

Favorites Activity Class:

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

When I click on the button to launch the favorites screen/activity and create the listview , the application exits with an error (was forced to quit ...). Any help or ideas will be appreciated. Thx.

EDIT:

Adb Log Errors:

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

Also , fixed this part :

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

still getting the same problem. EDIT 2:

Ok guys, thx for all the help so far...

I have furthermore changed this:

The new Favorites Page activity (modified):

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

The new Adapter class (modified):

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

And the new error log 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 for the help so far... still getting the same error though.

Update:

I'm guessing this is my main problem right now:

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

I'm guessing this has something to do with the Adapter that does not support the view. I am somewhat confused :p lol. Any ideas.

FINAL EDIT - SOLVED Thx for all the help guys. Its finally working and it looks great.

The main problems where the way I assigned the drawables to the ImageViews which caused problems when doing the inflate. Thx Sam for pointing that out. Another major problem was that I had to add the false parameter to the inflate method to not copy it to the root. Thx Angelo for pointing this out.

Upvotes: 2

Views: 2347

Answers (4)

yugidroid
yugidroid

Reputation: 6690

Why do you have the getCount() method, which should return a int value throwing an exception? That seems preety awkward. Instead of you should do:

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

That method is responsible for the number of lines that your ListView will going to have, ie, if yourDataArray has a size = 7 this means you will have 7 lines in the ListView.

EDIT:

Here is your solution:

  1. Replace getItem() method with:

     public Object getItem(int arg0)
     {
         return arg0;
     }
    
  2. Replace your adapter getView() method with the code below.

    @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;
    }
    

    Use a ViewHolder. Be sure you define a ViewHolder inner class like:

    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;
    }
    

Upvotes: 1

Sam
Sam

Reputation: 86958

Without the LogCat we can only guess at what errors you have...

1) You are extending a ListActivity:

public class Page_Favorites extends ListActivity

This requires that you have a ListView with the attribute android:id="@android:id/list" in the layout that you pass to setContentView(). I simply recommend you only extend an Activity:

public class Page_Favorites extends Activity

since your current code does not depend on a ListActivity.

2) Out of context:

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

You cannot reference findViewById() before you have created the Activity, this should be done in onCreate() after setContentView().

3) You should load your drawable into an ImageView like this:

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

I guessed at where you wanted the image... Is this what you meant to do?

And enough people have commented on getCount() already, so I won't reiterate it.

4) In your adapter's getView(), change this:

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

to this:

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

Upvotes: 3

AggelosK
AggelosK

Reputation: 4351

Here is your problem:

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

You should return the number of elements in the list. Something like this:

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

Also, what Sam said is another issue you should fix.

EDIT Seeing your adapter code i noticed that you are not using a ViewHolder. I strongly reccomend you to use it since it can leverage the performance of your listView significantly. Here is a nice link that explains all the basics about a listView. The above comment is just for performance but it is good to include it.

From the answer with the highest score of this SO question. Change this line:

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

with this:

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

and i think you will not have any problem.

Upvotes: 0

andrei_zaitcev
andrei_zaitcev

Reputation: 1458

Check this method:

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

Return value that's > 0. It helped me recently. I'm not sure about your problem, but just try.

Upvotes: 0

Related Questions