我想为我的 ListView 添加数据,但 getCount() 方法总是返回 0。
public class MySellingListAdapter extends ArrayAdapter<MySellingData>
{
private Context context;
private List<MySellingData> listSellingData;
public MySellingListAdapter (Context context, int resourceId, List<MySellingData> listSellingData)
{
super(context, resourceId, listSellingData);
this.context = context;
this.listSellingData = listSellingData;
}
@Override
public int getCount()
{
int size = listSellingData == null ? 0 : listSellingData.size();
Log.e("DD", "" + size);
return size;
}
}
我有一个 Fragment 类,我在其中设置了适配器:
@Override
protected void onCreate(Bundle bundle)
{
if (mySellingListAdapter == null)
mySellingListAdapter = new MySellingListAdapter(instance, R.layout.row_selling_item, listSellingData);
}
我有一个异步调用来获取数据:
private void loadData()
{
// ...
@Override void onPostExecute(Data... values)
{
mySellingListAdapter.notifyDataSetChanged();
}
}
0
0
0
0
0
0