Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get notifyDatasetChanged() to work with a ListAdapter?
    primarykey
    data
    text
    <p>Right now I use setAdapter to update my ListView, but I think the proper way is to use notifiyDatasetChanged() and I can't get that to work in my main class (it's in the adapter). Here is the error:</p> <p>The method notifyDatasetChanged() is undefined for the type ListAdapter</p> <p>I'm guessing there is a better way of doing this - can anyone point me in the right direction?</p> <p>Here's the relevant parts of my code:</p> <pre><code>public class ScoreList extends SherlockFragmentActivity { private ListView listViewScore; static List&lt;Score&gt; listScore = new ArrayList&lt;Score&gt;(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.score_list); ctx = this; listScore = dbh.getAllScores(); listViewScore = (ListView) findViewById(R.id.score_list); listViewScore.setAdapter(new ScoreListAdapter(ctx, R.layout.score_row_item, listScore)); listViewScore.getAdapter().notifyDatasetChanged(); //this is where I get the error } } </code></pre> <p>Here's the adapter:</p> <pre><code>public class ScoreListAdapter extends ArrayAdapter&lt;Score&gt; { private int resource; private LayoutInflater inflater; public ScoreListAdapter(Context ctx, int resourceId, List&lt;Score&gt; objects) { super(ctx, resourceId, objects); resource = resourceId; inflater = LayoutInflater.from(ctx); //context = ctx; } @Override public View getView(final int position, View convertView, ViewGroup parent) { convertView = (LinearLayout) inflater.inflate(resource, null); Score score = getItem(position); TextView txtName = (TextView) convertView.findViewById(R.id.name); txtName.setText(score.getName()); TextView txtScoreChange = (TextView) convertView .findViewById(R.id.scoreChange); int scoreChange = Integer.parseInt(score.getScoreChange()); if (scoreChange &gt; 0) txtScoreChange.setText("+" + scoreChange); else if (scoreChange &lt; 0) txtScoreChange.setText("" + scoreChange); else txtScoreChange.setText(""); TextView txtScoreTotal = (TextView) convertView .findViewById(R.id.scoreTotal); txtScoreTotal.setText(score.getScoreTotal()); final LinearLayout currentRow = (LinearLayout) convertView .findViewById(R.id.scoreRowLayout); notifyDataSetChanged(); return convertView; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload