use of com.asksven.betterbatterystats.adapters.StatsAdapter in project BetterBatteryStats by asksven.
the class StatsActivity method setListViewAdapter.
/**
* In order to refresh the ListView we need to re-create the Adapter
* (should be the case but notifyDataSetChanged doesn't work so
* we recreate and set a new one)
*/
private void setListViewAdapter() throws Exception {
LinearLayout notificationPanel = (LinearLayout) findViewById(R.id.Notification);
ListView listView = (ListView) findViewById(android.R.id.list);
ArrayList<StatElement> myStats = StatsProvider.getInstance().getStatList(m_iStat, m_refFromName, m_iSorting, m_refToName);
if ((myStats != null) && (!myStats.isEmpty())) {
// check if notification
if (myStats.get(0) instanceof Notification) {
// Show Panel
notificationPanel.setVisibility(View.VISIBLE);
// Hide list
listView.setVisibility(View.GONE);
// set Text
TextView tvNotification = (TextView) findViewById(R.id.TextViewNotification);
tvNotification.setText(myStats.get(0).getName());
} else {
// hide Panel
notificationPanel.setVisibility(View.GONE);
// Show list
listView.setVisibility(View.VISIBLE);
}
}
// make sure we only instanciate when the reference does not exist
if (m_listViewAdapter == null) {
m_listViewAdapter = new StatsAdapter(this, myStats, StatsActivity.this);
Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, StatsActivity.this);
Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, StatsActivity.this);
long sinceMs = StatsProvider.getInstance().getSince(myReferenceFrom, myReferenceTo);
m_listViewAdapter.setTotalTime(sinceMs);
setListAdapter(m_listViewAdapter);
}
}
Aggregations