jah*_*h15 3 android android-arrayadapter android-listview custom-adapter pull-to-refresh
使用Chris Banes的PullToRefresh库,我的自定义适配器的getView()方法没有被调用.这段代码工作正常,不使用他的库,并调用getView().我一直在调查这几天,无法弄清楚出了什么问题.任何反馈将不胜感激!
MyActivity.java
MyAdapter adapter = new MyAdapter(this, data);
// the following toast displays the correct count
Toast.makeText("MyActivity", adapter.getCount(), Toast.LENGTH_SHORT).show();
myListView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
MyAdapter.java
public class MyAdapter extends ArrayAdapter<Object> {
private ArrayList<Object> data;
private LayoutInflater vi;
private Context context;
public MyAdapter(Context context, ArrayList<Object> data) {
super(context, 0);
this.context = context;
this.data = data;
this.vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
static class ViewHolder {
...
}
@Override
public int getCount() {
return data.size();
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// not getting called
...
}
}
Run Code Online (Sandbox Code Playgroud)
Google IO 2013在ListView中进行了许多更改以优化结果.我遇到了类似的问题,我没有调用自定义适配器的getView()函数.
根据新的更改,如果您使用"wrap_content"作为视图的layout_height,则只有在用户滚动列表时才会调用getView().因此,请使用"fill_parent"作为视图的layout_height.它会解决你的问题.
使用,
android:layout_height="fill_parent"
Run Code Online (Sandbox Code Playgroud)
而不是使用
android:layout_height="wrap_content"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3292 次 |
| 最近记录: |