Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未调用ArrayAdapter getView_Android_Android Listview_Android Arrayadapter_Android 4.0 Ice Cream Sandwich - Fatal编程技术网

Android 未调用ArrayAdapter getView

Android 未调用ArrayAdapter getView,android,android-listview,android-arrayadapter,android-4.0-ice-cream-sandwich,Android,Android Listview,Android Arrayadapter,Android 4.0 Ice Cream Sandwich,我有一个自定义的ArrayAdapter,即使调用了我的getCount方法(我返回数组的计数,在示例中,该计数为181),也不会调用我的getView。这是从今天开始的,似乎是随机发生的。有时,它确实会被调用并完美地显示出来。有时,在加载数据后,它只是保持空白。这里有几件事: 我在getCount中设置了一个断点,它返回一个正数 我已经将列表的背景色设置为某种颜色,它显示得非常完美,用它的背景色填充屏幕。所以没有布局问题 我在setAdapter方法中设置了一个断点,它在UI线程上正常被调用

我有一个自定义的
ArrayAdapter
,即使调用了我的
getCount
方法(我返回数组的计数,在示例中,该计数为181),也不会调用我的
getView
。这是从今天开始的,似乎是随机发生的。有时,它确实会被调用并完美地显示出来。有时,在加载数据后,它只是保持空白。这里有几件事:

  • 我在
    getCount
    中设置了一个断点,它返回一个正数
  • 我已经将列表的背景色设置为某种颜色,它显示得非常完美,用它的背景色填充屏幕。所以没有布局问题
  • 我在
    setAdapter
    方法中设置了一个断点,它在UI线程上正常被调用。(如果没有调用此函数,
    getCount
    也不会被调用)
有趣的是,这种情况并不总是发生。几分钟前,我重新启动了我的设备(Galaxy S3,如果有帮助的话),问题消失了,但现在,当我写这些问题时,它又回来了。我已经检查了我的网络连接,没有问题(无论如何我都成功地获取了项目数组)。我见过很多关于这个具体问题的问题,但没有一个能解决我的问题。如果有帮助的话,我会用ICS

这是我的构造函数:

protected List<Map<String, Object>> objects;
protected Map<String, Object> user;

public FeedAdapter(Context context, List<Map<String, Object>> objects, Map<String, Object> attachedUser) {
    super(context, 0, objects);
    this.objects = objects;
    this.user = attachedUser;
}

什么可能导致问题?

更改布局(ListView)的高度和宽度以匹配父级。

首先,请检查getCount()中的返回值,确保已在getCount()中返回数据(列表、ArrayList的大小)

其次,确保任何其他视图TextView、view和ListView不能重叠,否则getView无法呈现数据或将数据绑定到ListView的ListContent。因此,在CustomAdapter中有数据(List、ArrayList),这就是为什么不调用getView()


我希望这将有助于您的工作。

您是否通过调用super()将数据正确地传递给构造函数中的super类?如果您使用的是
ArrayAdapter
,则无需重写getCount。此外,您还可以尝试扩展
BaseAdapter
,而不是
ArrayAdapter
。@AbhishekV我已经添加了构造函数代码。我认为这是正确的,但请看一看。只是检查一下,从网络加载数据后,您是否调用notifydatasetchanged?@CanPoyrazoğlu构造函数似乎是正确的。@prashant加载数据后,我已经在用加载的数据创建适配器了。(是的,我知道,也许不是最好的模式,但无论如何)
 dataSource = (ArrayList<Map<String, Object>>) task.getResult();
 FeedAdapter adapter = new FeedAdapter(getActivity(), dataSource, getUser());
 ListView list = (ListView) rootView.findViewById(R.id.listView);
 list.setOnItemClickListener(self);
 list.setAdapter(adapter);