刷新expandableListView

时间:2015-05-18 20:44:20

标签: android expandablelistview

我知道在我面前问过这个问题,但是notifyDataSetChanged();对我不起作用,或者我使用它错了>?

@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);

}

}

我无法弄清楚我做错了什么,有人可以帮我吗?

0 个答案:

没有答案