Android 刷新expandableListView
我知道这个问题是在我之前提过的,但是notifydatasetchange();对我不起作用,还是我用错了>Android 刷新expandableListView,android,expandablelistview,Android,Expandablelistview,我知道这个问题是在我之前提过的,但是notifydatasetchange();对我不起作用,还是我用错了> @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // preparing list data prepareListData(
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// preparing list data
prepareListData();
listAdapter1 = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter1);
// Listview Group expanded listener
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Expanded",
Toast.LENGTH_SHORT).show();
listAdapter1.notifyDataSetChanged();
prepareListData();
System.out.println(listAdapter1.getChildrenCount(0) + "pirmutinis");
}
});
}
以及准备列表数据的函数
public void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
listDataHeader.add("Paired devices");
List<String> deviceList = new ArrayList<String>();
// top250.add("The Shawshank Redemption");
// listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
pairedDevices = mBluetoothAdapter.getBondedDevices();
for (int i = 0; i<=pairedDevices.size(); i++) {
listDataChild.clear();
}
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
mDevice = device;
System.out.println(mDevice.getName());
Toast.makeText(this, mDevice.getName(), Toast.LENGTH_SHORT)
.show();
deviceList.add(mDevice.getName()+ "\n" + mDevice.getAddress());
}
}
//listDataChild.remove(aa)
System.out.println(deviceList.size() + "paskutinis");
listDataChild.put(listDataHeader.get(0), deviceList);
}
public void prepareListData(){
listDataHeader=新的ArrayList();
listDataChild=newHashMap();
添加(“配对设备”);
List deviceList=new ArrayList();
//top250.添加(“肖申克的救赎”);
//listDataChild.put(listDataHeader.get(0),top250);//头,子数据
pairedDevices=mBluetoothAdapter.getBondedDevices();
对于(int i=0;i 0){
用于(蓝牙设备:pairedDevices){
mDevice=设备;
System.out.println(mDevice.getName());
Toast.makeText(this,mDevice.getName(),Toast.LENGTH\u SHORT)
.show();
添加(mDevice.getName()+“\n”+mDevice.getAddress());
}
}
//listDataChild.remove(aa)
System.out.println(deviceList.size()+“paskutinis”);
listDataChild.put(listDataHeader.get(0),deviceList);
}
}
我想不出我做错了什么,谁能帮帮我吗