从云端读取信息后传到数据源,然后绑定数据适配器实现下拉刷新,有BUG求帮忙改正
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refreshList(); listList.setAdapter(mAdapter); listList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(ContentActivity.this, "you clicked", Toast.LENGTH_SHORT).show(); } }); Toast.makeText(ContentActivity.this, "刷新成功", Toast.LENGTH_SHORT).show(); // mAdapter.notifyDataSetChanged(); } }); } private void refreshList() { BmobQuery<Lost> query = new BmobQuery<Lost>(); query.order("-createdAt"); query.findObjects(this, new FindListener<Lost>() { @Override public void onSuccess(List<Lost> list) { mLostList.addAll(list); mAdapter = new LostAdapter(ContentActivity.this, mLostList); swipeRefresh.setRefreshing(false); Log.d(TAG, "onSuccess: " + "ccccccccccccccccccccccccccccccccccccccccccccccc"); } @Override public void onError(int i, String s) { Toast.makeText(ContentActivity.this, "刷新失败", Toast.LENGTH_SHORT).show(); Log.d(TAG, "onError: " + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); } }); }
以下是适配器
public class LostAdapter extends BaseAdapter{ private List<Lost> mList; private Context mContext; private LayoutInflater mLayoutInflater; public LostAdapter(Context context,List<Lost> list){ mContext = context; mList = list; mLayoutInflater = LayoutInflater.from(context); } @Override public int getCount() { return mList.size(); } @Override public Object getItem(int position) { return mList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder; if (convertView == null) { viewHolder = new ViewHolder(); convertView = mLayoutInflater.inflate(R.layout.list_item,null); viewHolder.mTvLostTitle = (TextView) convertView.findViewById(R.id.tv_title); viewHolder.mTvLostPhone = (TextView) convertView.findViewById(R.id.tv_phone); viewHolder.mTvLostDescribe = (TextView) convertView.findViewById(R.id.tv_describe); }else { viewHolder = (ViewHolder) convertView.getTag(); } Lost lost = mList.get(position); viewHolder.mTvLostTitle.setText(lost.getTitle()); viewHolder.mTvLostPhone.setText(lost.getPhone()); viewHolder.mTvLostDescribe.setText(lost.getDescribe()); return convertView; } private static class ViewHolder { public TextView mTvLostTitle; public TextView mTvLostPhone; public TextView mTvLostDescribe; } }
解决方案
40
viewholder你没settag的原因吧