正常的话很多人的代码可能会这样写:

1. 初始化

mListView = (ListView) findViewById(R.id.listview_dtclist);
        mDTCList = new ArrayList<VODTC>();
        mDTCListAdapter = new DTCListAdapter(Activity_DTCList.this, mDTCList);
        mListView.setAdapter(mDTCListAdapter);

 

2.取得数据:

mDTCList = ATGatewayClient.getDTCAlertList(app.user.token,
                    app.user.token_secret, app.user.userID,
                    app.deviceList.get(app.devicePosition).deviceID);

3.刷新ListView:

mDTCListAdapter.notifyDataSetChanged();

4. 其实是不起作用的 这样, 可以使用下面的方案让其起作用

mDTCListAdapter = new DTCListAdapter(Activity_DTCList.this,
                            mDTCList);
                    mListView.setAdapter(mDTCListAdapter);

 

但是如果这样写的话,notifyDataSetChanged就没有起作用了, 还是使用以下的文法吧..

正确的写法

1. 初始化

mListView = (ListView) findViewById(R.id.listview_dtclist);
    mDTCList = new ArrayList<VODTC>();
    mDTCListAdapter = new DTCListAdapter(Activity_DTCList.this, mDTCList);
    mListView.setAdapter(mDTCListAdapter);

 

2. 取得数据

List<VODTC> _mDTCList = ATGatewayClient.getDTCAlertList(app.user.token,
                    app.user.token_secret, app.user.userID,
                    app.deviceList.get(app.devicePosition).deviceID);
            mDTCList.addAll(_mDTCList);

3. 更新ListView

mDTCListAdapter.notifyDataSetChanged();