I am customizing a ListView.
The pull-to-refresh function runs directly from https://github.com/chrisbanes/Android-PullToRefresh
ListView displays images, so I created a custom adapter:
class mAdapter extends BaseAdapter{ public mAdapter(Context context){ // nothing to do } @Override public int getCount() { return mValues.size(); } @Override public Object getItem(int position) { return mValues.get(position); } @Override public long getItemId(int position) { return position; } @Override public boolean areAllItemsEnabled() { return false; } @Override public boolean isEnabled(int position) { return false; } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if(v == null){ LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.list_item, null); } ImageView iv = (ImageView) v.findViewById(R.id.imageView); if(iv != null){ displayImageInView(iv); iv.setClickable(true); iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context, "ImageView", Toast.LENGTH_SHORT).show(); } }); } return v; } }
in onCreate (), I get a listView and assign an adapter:
mListView = (PullToRefreshListView) findViewById(R.id.listView); mListView.setAdapter(new mAdapter(context));
After that, I add the image to mValues (URL to download the image from the Internet) and call notitiyDataSetChanged on the adapter.
in mListView.onRefresh (), I add the image to mValues.
This works smoothly to add the first image or even the first group of images (before calling mAdapter.notifyDataSetChanged ()). The update indicator is displayed and hidden as intended.
Strange things begin to happen when I try to add another image (or bunch) after that.
The refresh indicator shows the image is displayed as a list.
BUT: the update indicator never hides after that. "onRefreshComplete ()" is called, but doesn't seem to work properly the second time.
The user interface thread is not blocked, so operation is still possible. If I delete all items in mValues, notify the adapter and drag to refresh the image again, the image will be added correctly and the update indicator will be hidden.
Conclusion When updating, the update is only hidden if the list was empty before the update.
I really don't know where to look for a solution to this strange error.
Maybe someone who is familiar with the Chirs Banes Pull-To-Refresh library can help me here.
Thanks!