I am refering Android ListView Refresh Single Row
However, to use the above link technique, I have to make ListView visible to ArrayAdapter.
Currently, in order to have a very optimized way to update display in ListView, I need to do this to my ArrayAdapter
public PortfolioArrayAdapter(ListView listView, Activity activity, List<TransactionSummary> transactionSummaries) {
super(activity, R.layout.portfolio_management_row_layout, transactionSummaries);
this.activity = activity;
this.listView = listView;
...
}
// Do not use notifyDataSetChanged, as it will refresh entire ListView.
// We only want to update certain row.
private void refreshView(final int row) {
final int firstVisiblePosition = listView.getFirstVisiblePosition();
final int lastVisiblePosition = listView.getLastVisiblePosition();
if (row < firstVisiblePosition || row > lastVisiblePosition) {
return;
}
this.activity.runOnUiThread(new Runnable() {
public void run() {
final View view = listView.getChildAt(row - firstVisiblePosition);
// Refresh?
getView(row, view, listView);
}
});
}
However, I feel uncomfortable to pass ListView reference to ArrayAdapter, as I thought they should be independent from each others? (Due to MVC?)
Is there any better way I can let ListView Refresh Single Row?
In Java Swing, they did it in a pretty neat way. They provide the following method for a table model.
fireTableCellUpdated(row, col);
So, that model can tell view which row and col is being affected, without knowing who the view is.
In Andorid, my model (ArrayAdapter) needs to know, ListView is the view, only then my model can talk to the view.