Skip to content Skip to sidebar Skip to footer

Android: GetView In Adapter Never Called

Still geting my head around how adapters work and the structure. Im trying to show text (from server) in xml and the user should be able to edit that text and then send it back (to

Solution 1:

You didn't pass the array to the super constructor so the ArrayAdapter cannot report the correct number of items in its getCount() implementation.

Either override getCount() to return the number of elements in the array, or use an overload of the ArrayAdapter constructor that also takes in the array.


Solution 2:

You are using a different overloaded constructor than your actual constructor. That's fine however you need to Override the getCount method as at the moment it always returns 0.

Here's how:

@Override
public int getCount() {
    return list.size();
}

EDIT:

Now I noticed you are using a custom class Meal. You need to track it's count.

If the only items that it has is mango, apple, banana then you can simply return 3;

EDIT2:

The problem is that your Meal class cannot loop through objects, this proves it: foodItem1.setText(list.MealName);.

You want your class to be loopable like list.get(0).MealName, list.get(1).MealName...

Perhaps what you want is a list of Meal objects: List<Meal> meals = getMeals();.

At the moment (even if you could get the meal count), all your views will be the same as list.MealName and list.Meald doesn't change. Hope this somewhat clears it up.


Solution 3:

Normallly we populate data and than pass that data to the customAdapter something like following psuedo code:

data=getData();
CustomAdapter adapter=new CustomAdapter(context,data);

and inside custom adapter make sure you have override getCount() method properly.

normally it is implemented as this:

    getCount(){
       data.size()
    }

Post a Comment for "Android: GetView In Adapter Never Called"