今、私はListViewを更新するためにsetAdapterを使用していますが、notifiyDatasetChanged()を使用するのが適切な方法だと思っていますし、メインクラス(アダプタにあります)で動作させることもできません。ここでエラーがある:NotifyDatasetChanged()をListAdapterで使用するにはどうすればよいですか?
notifyDatasetChanged方法は()型ListAdapter
について定義されていません、私はこれを行うには良い方法があると推測している - 誰もが正しい方向に私を指すことができますか?
ここに私のコードの関連部分です。ここで
public class ScoreList extends SherlockFragmentActivity {
private ListView listViewScore;
static List<Score> listScore = new ArrayList<Score>();
@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
}
}
だアダプタ:
public class ScoreListAdapter extends ArrayAdapter<Score> {
private int resource;
private LayoutInflater inflater;
public ScoreListAdapter(Context ctx, int resourceId, List<Score> 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 > 0)
txtScoreChange.setText("+" + scoreChange);
else if (scoreChange < 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;
}
}
これは 'notifyDataSetChanged()'です。大文字であることがわかります。表示されている行に小文字の 's'があります。エラーがあります。 – Squonk
まず、notifyDatasetChangedの使用方法を知っておく必要があります。添付されているオブザーバーに、基礎となるデータが変更され、データセットを反映しているビューが更新されることを通知します。実装する前にこれを理解する... notifyDatasetChanged()は、アダプタデータ内のデータが更新されたか、または単に変更されたときに使用されます。アダプタに関連付けられたコレクションが変更されます。創造でそれを呼び出す必要はありません – Pragnani
私は創造でそれを呼び出すことはなかったので、私は多くのコードをカットした、ちょうどここでそのように見えた。 – GrilledCheese