如何在点击刷新按钮时刷新BaseAdapter

问题描述:

我想刷新BaseAdapter这是fragment。我使用BaseAdapter显示蓝牙列表。我想刷新刷新button点击此列表并希望在FragmentListview上显示。 我该怎么做?如何在点击刷新按钮时刷新BaseAdapter

+2

简单地尝试使用notifyDataSetChanged()通知适配器刷新listvew。 – yash786

+4

[如何刷新Android的listview?](https://stackoverflow.com/questions/2250770/how-to-refresh-android-listview)可能的重复 –

更新您的数据采集,比如数组或列表,并做BaseAdapter.notifyDataSetChanged();

试试这个。

public class PersonAdapter extends BaseAdapter { 
private ArrayList<PersonBean> mList; 
private Context mContext; 

public PersonAdapter(ArrayList<PersonBean> list, Context context) { 
    mList = list; 
    mContext = context; 
} 

public void refresh(ArrayList<PersonBean> list) { 
    mList = list; 
    notifyDataSetChanged(); 
} 
... 

当单击

mAdapter.refresh(mList);